mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
docs: Document Clutter's threading model
Be explicit on how to deal with threads and Clutter.
This commit is contained in:
parent
fc7bbf1abf
commit
17e3b526d5
@ -28,6 +28,62 @@
|
||||
*
|
||||
* Functions to retrieve various global Clutter resources and other utility
|
||||
* functions for mainloops, events and threads
|
||||
*
|
||||
* <refsect2 id="clutter-Threading-Model">
|
||||
* <title>Threading Model</title>
|
||||
* <para>Clutter is <emphasis>thread-aware</emphasis>: all operations
|
||||
* performed by Clutter are assumed to be under the big Clutter lock,
|
||||
* which is created when the threading is initialized through
|
||||
* clutter_threads_init().</para>
|
||||
* <example id="example-Thread-Init">
|
||||
* <title>Thread Initialization</title>
|
||||
* <para>The code below shows how to correctly initialize Clutter
|
||||
* in a multi-threaded environment. These operations are mandatory for
|
||||
* applications that wish to use threads with Clutter.</para>
|
||||
* <programlisting>
|
||||
* int
|
||||
* main (int argc, char *argv[])
|
||||
* {
|
||||
* /* initialize GLib's threading support */
|
||||
* g_thread_init (NULL);
|
||||
*
|
||||
* /* initialize Clutter's threading support */
|
||||
* clutter_threads_init ();
|
||||
*
|
||||
* /* initialize Clutter */
|
||||
* clutter_init (&argc, &argv);
|
||||
*
|
||||
* /* program code */
|
||||
*
|
||||
* /* acquire the main lock */
|
||||
* clutter_threads_enter ();
|
||||
*
|
||||
* /* start the main loop */
|
||||
* clutter_main ();
|
||||
*
|
||||
* /* release the main lock */
|
||||
* clutter_threads_leave ();
|
||||
*
|
||||
* /* clean up */
|
||||
* return 0;
|
||||
* }
|
||||
* </programlisting>
|
||||
* </example>
|
||||
* <para>This threading model has the caveat that it is only safe to call
|
||||
* Clutter's API when the lock has been acquired — which happens
|
||||
* between pairs of clutter_threads_enter() and clutter_threads_leave()
|
||||
* calls.</para>
|
||||
* <para>The only safe and portable way to use the Clutter API in a
|
||||
* multi-threaded environment is to never access the API from a thread that
|
||||
* did not call clutter_init() and clutter_main().</para>
|
||||
* <para>The common pattern for using threads with Clutter is to use worker
|
||||
* threads to perform blocking operations and then install idle or timeour
|
||||
* sources with the result when the thread finished.</para>
|
||||
* <para>Clutter provides thread-aware variants of g_idle_add() and
|
||||
* g_timeout_add() that acquire the Clutter lock before invoking the provided
|
||||
* callback: clutter_threads_add_idle() and
|
||||
* clutter_threads_add_timeout().</para>
|
||||
* </refsect2>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
Loading…
Reference in New Issue
Block a user