diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 579a791e6..90452482d 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -28,6 +28,62 @@ * * Functions to retrieve various global Clutter resources and other utility * functions for mainloops, events and threads + * + * + * Threading Model + * Clutter is thread-aware: 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(). + * + * Thread Initialization + * 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. + * + * 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; + * } + * + * + * 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. + * 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(). + * 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. + * 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(). + * */ #ifdef HAVE_CONFIG_H