From 6e9a1630357a21c6ef6357cdde324ae89a565826 Mon Sep 17 00:00:00 2001
From: Michael R Sweet
The awake() method sends a message pointer to the -main thread, causing any pending wait() call to -terminate so that the main thread can retrieve the message and -any pending redraws can be processed. +
The awake() method sends a message pointer to the main thread, causing any pending Fl::wait() call to terminate so that the main thread can retrieve the message and any pending redraws can be processed. -
Multiple calls to awake() will overwrite the same -message pointer. -thread_message() only returns -the last message stored by the last awake() call. +
Multiple calls to Fl::awake() will queue multiple pointers for the main thread to process, up to a system-defined (typically several thousand) depth. The default message handler saves the last message which can be accessed using the Fl::thread_message() function. Use the Fl::set_awake_cb() function to register your own thread message handler that is called for every message received by the main thread. -
See also: multithreading +
See also: multithreading.
Sets a function to handle thread messages sent via the Fl::awake() function.
+This chapter explains advanced programming and design topics that will help you to get the most out of FLTK.
-FLTK supports multithreaded application using a locking mechanism -based on "pthreads". We do not provide a threading interface -as part of the library. However a simple example how threads can -be implemented for all supported platforms can be found in -test/threads.h and test/threads.cxx. +
FLTK supports multithreaded application using a locking mechanism based on "pthreads". We do not provide a threading interface as part of the library. However a simple example how threads can be implemented for all supported platforms can be found in test/threads.h and test/threads.cxx. -
To use the locking mechanism, the command line version of FLTK -must be compiled with --enable-threads set during the -configure process. IDE-based versions of FLTK are -automatically compiled with locking enabled if possible. +
To use the locking mechanism, FLTK must be compiled with --enable-threads set during the configure process. IDE-based versions of FLTK are automatically compiled with locking enabled if possible. -
In main(), before calling Fl::run(), call -Fl::lock(). This will startup the runtime multithreading -support for your program. All callbacks and derived functions -like handle() and draw() will now be properly -locked. +
In main(), call Fl::lock() before Fl::run() to start the runtime multithreading support for your program. All callbacks and derived functions like handle() and draw() will now be properly locked.
main() {
@@ -56,34 +45,31 @@ in the following code:
FLTK supports multiple platforms, some of them which do not
allow any other but the main thread to handle system events and
open or close windows. The safe thing to do is to adhere to the
-following rulesi for threads on all operating systems.
+following rules for threads on all operating systems:
See also: +void awake(void *message), void lock(), void unlock(), -void awake(void *message), +void set_awake_cb(void (*cb)(void *), void *thread_message(). -