~bratsche/ubuntu/maverick/gtk+2.0/menu-activation-fix

« back to all changes in this revision

Viewing changes to docs/reference/gdk/html/gdk-Threads.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-06-13 10:00:13 UTC
  • mto: (72.2.1 lenny) (1.5.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20070613100013-qstao3cwpm6xdlxc
Tags: upstream-2.11.2
ImportĀ upstreamĀ versionĀ 2.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
19
19
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
20
20
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
 
21
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
21
22
</head>
22
23
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
23
24
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
28
29
<th width="100%" align="center">GDK Reference Manual</th>
29
30
<td><a accesskey="n" href="gdk-Input.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
30
31
</tr>
31
 
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2792299" class="shortcut">Top</a>
 
32
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2849740" class="shortcut">Top</a>
32
33
                  &#160;|&#160;
33
 
                  <a href="#id2792419" class="shortcut">Description</a></nobr></td></tr>
 
34
                  <a href="#id2850034" class="shortcut">Description</a></nobr></td></tr>
34
35
</table>
35
36
<div class="refentry" lang="en">
36
37
<a name="gdk-Threads"></a><div class="titlepage"></div>
37
38
<div class="refnamediv"><table width="100%"><tr>
38
39
<td valign="top">
39
40
<h2>
40
 
<a name="id2792299"></a><span class="refentrytitle">Threads</span>
 
41
<a name="id2849740"></a><span class="refentrytitle">Threads</span>
41
42
</h2>
42
43
<p>Threads &#8212; Functions for using GDK in multi-threaded programs</p>
43
44
</td>
58
59
extern              GMutex *<a href="gdk-Threads.html#gdk-threads-mutex">gdk_threads_mutex</a>;
59
60
void                <a href="gdk-Threads.html#gdk-threads-set-lock-functions">gdk_threads_set_lock_functions</a>      (GCallback enter_fn,
60
61
                                                         GCallback leave_fn);
 
62
guint               <a href="gdk-Threads.html#gdk-threads-add-idle">gdk_threads_add_idle</a>                (GSourceFunc function,
 
63
                                                         gpointer data);
 
64
guint               <a href="gdk-Threads.html#gdk-threads-add-idle-full">gdk_threads_add_idle_full</a>           (gint priority,
 
65
                                                         GSourceFunc function,
 
66
                                                         gpointer data,
 
67
                                                         GDestroyNotify notify);
 
68
guint               <a href="gdk-Threads.html#gdk-threads-add-timeout">gdk_threads_add_timeout</a>             (guint interval,
 
69
                                                         GSourceFunc function,
 
70
                                                         gpointer data);
 
71
guint               <a href="gdk-Threads.html#gdk-threads-add-timeout-full">gdk_threads_add_timeout_full</a>        (gint priority,
 
72
                                                         guint interval,
 
73
                                                         GSourceFunc function,
 
74
                                                         gpointer data,
 
75
                                                         GDestroyNotify notify);
61
76
 
62
77
</pre>
63
78
</div>
64
79
<div class="refsect1" lang="en">
65
 
<a name="id2792419"></a><h2>Description</h2>
 
80
<a name="id2850034"></a><h2>Description</h2>
66
81
<p>
67
82
For thread safety, GDK relies on the thread primitives in GLib, 
68
83
and on the thread-safe GLib main loop.
290
305
</pre></div>
291
306
</div>
292
307
<div class="refsect1" lang="en">
293
 
<a name="id2792763"></a><h2>Details</h2>
 
308
<a name="id2849646"></a><h2>Details</h2>
294
309
<div class="refsect2" lang="en">
295
 
<a name="id2792773"></a><h3>
 
310
<a name="id2849656"></a><h3>
296
311
<a name="GDK-THREADS-ENTER:CAPS"></a>GDK_THREADS_ENTER()</h3>
297
 
<a class="indexterm" name="id2792787"></a><pre class="programlisting">#define             GDK_THREADS_ENTER()</pre>
 
312
<a class="indexterm" name="id2849670"></a><pre class="programlisting">#define             GDK_THREADS_ENTER()</pre>
298
313
<p>
299
314
This macro marks the beginning of a critical section in which GDK and GTK+
300
315
functions can be called.  Only one thread at a time can be in such a
305
320
</div>
306
321
<hr>
307
322
<div class="refsect2" lang="en">
308
 
<a name="id2792827"></a><h3>
 
323
<a name="id2849710"></a><h3>
309
324
<a name="GDK-THREADS-LEAVE:CAPS"></a>GDK_THREADS_LEAVE()</h3>
310
 
<a class="indexterm" name="id2792840"></a><pre class="programlisting">#define             GDK_THREADS_LEAVE()</pre>
 
325
<a class="indexterm" name="id2849723"></a><pre class="programlisting">#define             GDK_THREADS_LEAVE()</pre>
311
326
<p>
312
327
This macro marks the end of a critical section 
313
328
begun with <a href="gdk-Threads.html#GDK-THREADS-ENTER:CAPS"><span class="type">GDK_THREADS_ENTER</span></a>.
315
330
</div>
316
331
<hr>
317
332
<div class="refsect2" lang="en">
318
 
<a name="id2792865"></a><h3>
 
333
<a name="id2850612"></a><h3>
319
334
<a name="gdk-threads-init"></a>gdk_threads_init ()</h3>
320
 
<a class="indexterm" name="id2792877"></a><pre class="programlisting">void                gdk_threads_init                    (void);</pre>
 
335
<a class="indexterm" name="id2850625"></a><pre class="programlisting">void                gdk_threads_init                    (void);</pre>
321
336
<p>
322
337
Initializes GDK so that it can be used from multiple threads
323
338
in conjunction with <a href="gdk-Threads.html#gdk-threads-enter"><code class="function">gdk_threads_enter()</code></a> and <a href="gdk-Threads.html#gdk-threads-leave"><code class="function">gdk_threads_leave()</code></a>.
332
347
</div>
333
348
<hr>
334
349
<div class="refsect2" lang="en">
335
 
<a name="id2792951"></a><h3>
 
350
<a name="id2850698"></a><h3>
336
351
<a name="gdk-threads-enter"></a>gdk_threads_enter ()</h3>
337
 
<a class="indexterm" name="id2792964"></a><pre class="programlisting">void                gdk_threads_enter                   (void);</pre>
 
352
<a class="indexterm" name="id2850711"></a><pre class="programlisting">void                gdk_threads_enter                   (void);</pre>
338
353
<p>
339
354
This macro marks the beginning of a critical section
340
355
in which GDK and GTK+ functions can be called.
344
359
</div>
345
360
<hr>
346
361
<div class="refsect2" lang="en">
347
 
<a name="id2792988"></a><h3>
 
362
<a name="id2850735"></a><h3>
348
363
<a name="gdk-threads-leave"></a>gdk_threads_leave ()</h3>
349
 
<a class="indexterm" name="id2793001"></a><pre class="programlisting">void                gdk_threads_leave                   (void);</pre>
 
364
<a class="indexterm" name="id2850748"></a><pre class="programlisting">void                gdk_threads_leave                   (void);</pre>
350
365
<p>
351
366
Leaves a critical region begun with <a href="gdk-Threads.html#gdk-threads-enter"><code class="function">gdk_threads_enter()</code></a>. 
352
367
</p>
353
368
</div>
354
369
<hr>
355
370
<div class="refsect2" lang="en">
356
 
<a name="id2793033"></a><h3>
 
371
<a name="id2850781"></a><h3>
357
372
<a name="gdk-threads-mutex"></a>gdk_threads_mutex</h3>
358
 
<a class="indexterm" name="id2793049"></a><pre class="programlisting">extern GMutex *gdk_threads_mutex; /* private */
 
373
<a class="indexterm" name="id2850796"></a><pre class="programlisting">extern GMutex *gdk_threads_mutex; /* private */
359
374
</pre>
360
375
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
361
376
<h3 class="title">Warning</h3>
368
383
</div>
369
384
<hr>
370
385
<div class="refsect2" lang="en">
371
 
<a name="id2793107"></a><h3>
 
386
<a name="id2850855"></a><h3>
372
387
<a name="gdk-threads-set-lock-functions"></a>gdk_threads_set_lock_functions ()</h3>
373
 
<a class="indexterm" name="id2793123"></a><pre class="programlisting">void                gdk_threads_set_lock_functions      (GCallback enter_fn,
 
388
<a class="indexterm" name="id2850871"></a><pre class="programlisting">void                gdk_threads_set_lock_functions      (GCallback enter_fn,
374
389
                                                         GCallback leave_fn);</pre>
375
390
<p>
376
391
Allows the application to replace the standard method that
419
434
<p class="since">Since  2.4
420
435
</p>
421
436
</div>
 
437
<hr>
 
438
<div class="refsect2" lang="en">
 
439
<a name="id2851049"></a><h3>
 
440
<a name="gdk-threads-add-idle"></a>gdk_threads_add_idle ()</h3>
 
441
<a class="indexterm" name="id2851064"></a><pre class="programlisting">guint               gdk_threads_add_idle                (GSourceFunc function,
 
442
                                                         gpointer data);</pre>
 
443
<p>
 
444
A wrapper for the common usage of <a href="gdk-Threads.html#gdk-threads-add-idle-full"><code class="function">gdk_threads_add_idle_full()</code></a> 
 
445
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT_IDLE</span>.
 
446
</p>
 
447
<p>
 
448
See <a href="gdk-Threads.html#gdk-threads-add-idle-full"><code class="function">gdk_threads_add_idle_full()</code></a>.</p>
 
449
<p>
 
450
 
 
451
</p>
 
452
<div class="variablelist"><table border="0">
 
453
<col align="left" valign="top">
 
454
<tbody>
 
455
<tr>
 
456
<td><span class="term"><em class="parameter"><code>function</code></em>&#160;:</span></td>
 
457
<td> function to call
 
458
</td>
 
459
</tr>
 
460
<tr>
 
461
<td><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></td>
 
462
<td>     data to pass to <em class="parameter"><code>function</code></em>
 
463
</td>
 
464
</tr>
 
465
<tr>
 
466
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
 
467
<td> the ID (greater than 0) of the event source.
 
468
 
 
469
</td>
 
470
</tr>
 
471
</tbody>
 
472
</table></div>
 
473
<p class="since">Since  2.12
 
474
</p>
 
475
</div>
 
476
<hr>
 
477
<div class="refsect2" lang="en">
 
478
<a name="id2851197"></a><h3>
 
479
<a name="gdk-threads-add-idle-full"></a>gdk_threads_add_idle_full ()</h3>
 
480
<a class="indexterm" name="id2851213"></a><pre class="programlisting">guint               gdk_threads_add_idle_full           (gint priority,
 
481
                                                         GSourceFunc function,
 
482
                                                         gpointer data,
 
483
                                                         GDestroyNotify notify);</pre>
 
484
<p>
 
485
Adds a function to be called whenever there are no higher priority
 
486
events pending.  If the function returns <code class="literal">FALSE</code> it is automatically
 
487
removed from the list of event sources and will not be called again.
 
488
</p>
 
489
<p>
 
490
This variant of <code class="function">g_idle_add_full()</code> calls <em class="parameter"><code>function</code></em> with the GDK lock
 
491
held. It can be thought of a MT-safe version for GTK+ widgets for the 
 
492
following use case, where you have to worry about <code class="function">idle_callback()</code>
 
493
running in thread A and accessing <em class="parameter"><code>self</code></em> after it has been finalized
 
494
in thread B:
 
495
</p>
 
496
<p>
 
497
</p>
 
498
<div class="informalexample"><pre class="programlisting">
 
499
static gboolean idle_callback (gpointer data)
 
500
{
 
501
   SomeWidget *self = data;
 
502
    
 
503
   /* do stuff with self */
 
504
    
 
505
   self-&gt;idle_id = 0;
 
506
   
 
507
   return FALSE;
 
508
}
 
509
 
 
510
static void some_widget_do_stuff_later (SomeWidget *self)
 
511
{
 
512
   self-&gt;idle_id = g_idle_add (idle_callback, self)
 
513
}
 
514
  
 
515
static void some_widget_finalize (GObject *object)
 
516
{
 
517
   SomeWidget *self = SOME_WIDGET(object);
 
518
   
 
519
   if (self-&gt;idle_id)
 
520
     g_source_remove (self-&gt;idle_id);
 
521
   
 
522
   G_OBJECT_CLASS (parent_class)-&gt;finalize (object);
 
523
}
 
524
</pre></div>
 
525
<p>
 
526
 
 
527
</p>
 
528
<div class="variablelist"><table border="0">
 
529
<col align="left" valign="top">
 
530
<tbody>
 
531
<tr>
 
532
<td><span class="term"><em class="parameter"><code>priority</code></em>&#160;:</span></td>
 
533
<td> the priority of the idle source. Typically this will be in the
 
534
           range btweeen <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>
 
535
</td>
 
536
</tr>
 
537
<tr>
 
538
<td><span class="term"><em class="parameter"><code>function</code></em>&#160;:</span></td>
 
539
<td> function to call
 
540
</td>
 
541
</tr>
 
542
<tr>
 
543
<td><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></td>
 
544
<td>     data to pass to <em class="parameter"><code>function</code></em>
 
545
</td>
 
546
</tr>
 
547
<tr>
 
548
<td><span class="term"><em class="parameter"><code>notify</code></em>&#160;:</span></td>
 
549
<td>   function to call when the idle is removed, or <a
 
550
href="../liboil/liboil-liboiljunk.html#NULL:CAPS"
 
551
><code class="literal">NULL</code></a>
 
552
</td>
 
553
</tr>
 
554
<tr>
 
555
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
 
556
<td> the ID (greater than 0) of the event source.
 
557
 
 
558
</td>
 
559
</tr>
 
560
</tbody>
 
561
</table></div>
 
562
<p class="since">Since  2.12
 
563
</p>
 
564
</div>
 
565
<hr>
 
566
<div class="refsect2" lang="en">
 
567
<a name="id2851462"></a><h3>
 
568
<a name="gdk-threads-add-timeout"></a>gdk_threads_add_timeout ()</h3>
 
569
<a class="indexterm" name="id2851478"></a><pre class="programlisting">guint               gdk_threads_add_timeout             (guint interval,
 
570
                                                         GSourceFunc function,
 
571
                                                         gpointer data);</pre>
 
572
<p>
 
573
A wrapper for the common usage of <a href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a> 
 
574
assigning the default priority, <span class="type">G_PRIORITY_DEFAULT</span>.
 
575
</p>
 
576
<p>
 
577
See <a href="gdk-Threads.html#gdk-threads-add-timeout-full"><code class="function">gdk_threads_add_timeout_full()</code></a>.</p>
 
578
<p>
 
579
 
 
580
</p>
 
581
<div class="variablelist"><table border="0">
 
582
<col align="left" valign="top">
 
583
<tbody>
 
584
<tr>
 
585
<td><span class="term"><em class="parameter"><code>interval</code></em>&#160;:</span></td>
 
586
<td> the time between calls to the function, in milliseconds
 
587
            (1/1000ths of a second)
 
588
</td>
 
589
</tr>
 
590
<tr>
 
591
<td><span class="term"><em class="parameter"><code>function</code></em>&#160;:</span></td>
 
592
<td> function to call
 
593
</td>
 
594
</tr>
 
595
<tr>
 
596
<td><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></td>
 
597
<td>     data to pass to <em class="parameter"><code>function</code></em>
 
598
</td>
 
599
</tr>
 
600
<tr>
 
601
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
 
602
<td> the ID (greater than 0) of the event source.
 
603
 
 
604
</td>
 
605
</tr>
 
606
</tbody>
 
607
</table></div>
 
608
<p class="since">Since  2.12
 
609
</p>
 
610
</div>
 
611
<hr>
 
612
<div class="refsect2" lang="en">
 
613
<a name="id2851633"></a><h3>
 
614
<a name="gdk-threads-add-timeout-full"></a>gdk_threads_add_timeout_full ()</h3>
 
615
<a class="indexterm" name="id2851649"></a><pre class="programlisting">guint               gdk_threads_add_timeout_full        (gint priority,
 
616
                                                         guint interval,
 
617
                                                         GSourceFunc function,
 
618
                                                         gpointer data,
 
619
                                                         GDestroyNotify notify);</pre>
 
620
<p>
 
621
Sets a function to be called at regular intervals holding the GDK lock,
 
622
with the given priority.  The function is called repeatedly until it 
 
623
returns <code class="literal">FALSE</code>, at which point the timeout is automatically destroyed 
 
624
and the function will not be called again.  The <em class="parameter"><code>notify</code></em> function is
 
625
called when the timeout is destroyed.  The first call to the
 
626
function will be at the end of the first <em class="parameter"><code>interval</code></em>.
 
627
</p>
 
628
<p>
 
629
Note that timeout functions may be delayed, due to the processing of other
 
630
event sources. Thus they should not be relied on for precise timing.
 
631
After each call to the timeout function, the time of the next
 
632
timeout is recalculated based on the current time and the given interval
 
633
(it does not try to 'catch up' time lost in delays).
 
634
</p>
 
635
<p>
 
636
This variant of <code class="function">g_timeout_add_full()</code> can be thought of a MT-safe version 
 
637
for GTK+ widgets for the following use case:
 
638
</p>
 
639
<p>
 
640
</p>
 
641
<div class="informalexample"><pre class="programlisting">
 
642
static gboolean timeout_callback (gpointer data)
 
643
{
 
644
   SomeWidget *self = data;
 
645
   
 
646
   /* do stuff with self */
 
647
   
 
648
   self-&gt;timeout_id = 0;
 
649
   
 
650
   return FALSE;
 
651
}
 
652
 
 
653
static void some_widget_do_stuff_later (SomeWidget *self)
 
654
{
 
655
   self-&gt;timeout_id = g_timeout_add (timeout_callback, self)
 
656
}
 
657
 
 
658
static void some_widget_finalize (GObject *object)
 
659
{
 
660
   SomeWidget *self = SOME_WIDGET(object);
 
661
   
 
662
   if (self-&gt;timeout_id)
 
663
     g_source_remove (self-&gt;timeout_id);
 
664
   
 
665
   G_OBJECT_CLASS (parent_class)-&gt;finalize (object);
 
666
}
 
667
</pre></div>
 
668
<p>
 
669
 
 
670
</p>
 
671
<div class="variablelist"><table border="0">
 
672
<col align="left" valign="top">
 
673
<tbody>
 
674
<tr>
 
675
<td><span class="term"><em class="parameter"><code>priority</code></em>&#160;:</span></td>
 
676
<td> the priority of the timeout source. Typically this will be in the
 
677
           range between <span class="type">G_PRIORITY_DEFAULT_IDLE</span> and <span class="type">G_PRIORITY_HIGH_IDLE</span>.
 
678
</td>
 
679
</tr>
 
680
<tr>
 
681
<td><span class="term"><em class="parameter"><code>interval</code></em>&#160;:</span></td>
 
682
<td> the time between calls to the function, in milliseconds
 
683
            (1/1000ths of a second)
 
684
</td>
 
685
</tr>
 
686
<tr>
 
687
<td><span class="term"><em class="parameter"><code>function</code></em>&#160;:</span></td>
 
688
<td> function to call
 
689
</td>
 
690
</tr>
 
691
<tr>
 
692
<td><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></td>
 
693
<td>     data to pass to <em class="parameter"><code>function</code></em>
 
694
</td>
 
695
</tr>
 
696
<tr>
 
697
<td><span class="term"><em class="parameter"><code>notify</code></em>&#160;:</span></td>
 
698
<td>   function to call when the timeout is removed, or <a
 
699
href="../liboil/liboil-liboiljunk.html#NULL:CAPS"
 
700
><code class="literal">NULL</code></a>
 
701
</td>
 
702
</tr>
 
703
<tr>
 
704
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
 
705
<td> the ID (greater than 0) of the event source.
 
706
 
 
707
</td>
 
708
</tr>
 
709
</tbody>
 
710
</table></div>
 
711
<p class="since">Since  2.12
 
712
</p>
 
713
</div>
422
714
</div>
423
715
</div>
424
716
</body>