diff --git a/CHANGES b/CHANGES index d120e1040..1b99f7472 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ CHANGES IN FLTK 1.1.8 - Documentation fixes (STR #1454, STR #1455, STR #1456, STR #1457, STR #1458, STR #1460, STR #1481, STR #1578) + - Added Fl::set_awake_cb() to set a handler for thread + messages (STR #1536) - Added "mute sound" option to Sudoku game. - Updated the bundled zlib to v1.2.3. - Updated the bundled libpng to v1.2.16. diff --git a/FL/Fl.H b/FL/Fl.H index 1d4f67995..8c07365e6 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -78,6 +78,7 @@ public: // should be private! static void damage(int d) {damage_ = d;} static void (*idle)(); + static void (*awake_cb)(void *); static const char* scheme_; static Fl_Image* scheme_bg_; @@ -266,6 +267,7 @@ public: static void lock(); static void unlock(); static void awake(void* message = 0); + static void set_awake_cb(void (*cb)(void *)) { awake_cb = cb; } static void* thread_message(); // Widget deletion: diff --git a/documentation/Fl.html b/documentation/Fl.html index 281ef7b8a..24d5be118 100644 --- a/documentation/Fl.html +++ b/documentation/Fl.html @@ -126,6 +126,7 @@ state information and global methods for the current application.
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(). -