From 18f2016b1f743068cd3d4bb9740845c2d55af3f3 Mon Sep 17 00:00:00 2001
From: Matthias Melcher
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 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. +
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 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. + +
The second form of awake() registers a function that will be +called by the main thread during the next message handling cycle. +awake() will return 0 if the callback function was registered, +and -1 if registration failed. Over a thousand awake callbacks can be +registered simultaneously.
See also: multithreading. @@ -1169,10 +1183,6 @@ of this.
Sets a function to handle thread messages sent via the Fl::awake() function.
-You can now start as many threads as you like. From within a thread (other than the main thread) FLTK calls must be wrapped -with calls to Fl::lock() and Fl::unlock(): +with calls to Fl::lock() +and Fl::unlock():
Fl::lock(); // avoid conflicting calls
@@ -39,27 +40,28 @@ with calls to Fl::lock() and Fl::awake(msg):
+You can send messages from child threads to the main thread
+using Fl::awake(msg):
void *msg; // "msg" is a pointer to your message
Fl::awake(msg); // send "msg" to main thread
-These messages can be read by the main thread using Fl::thread_message() or by registering a message callback with Fl::set_awake_cb():
+You can also tell the main thread to call a function for you
+as soon as possible by using
+Fl::awake(callback, userdata):
- void message_cb(void *msg) {
- ... do something with "msg" ...
+ void do_something(void *userdata) {
+ // running with the main thread
}
- int main() {
- Fl::lock();
- Fl::set_awake_cb(message_cb);
- /* run thread */
- return (Fl::run());
- }
+ // running in another thread
+ void *data; // "data" is a pointer to your user data
+ Fl::awake(do_something, data); // call something in main thread
+
FLTK supports multiple platforms, some of them which do not
allow any other but the main thread to handle system events and
@@ -86,7 +88,6 @@ related methods that will handle system messages
See also:
void awake(void *message),
void lock(),
-void set_awake_cb(void (*cb)(void *),
void *thread_message(),
void unlock().
--
cgit v1.2.3