FLTK 1.4.0
Multithreading support functions

fl multithreading support functions declared in <FL/Fl.H> More...

Functions

static int Fl::awake (Fl_Awake_Handler cb, void *message=0)
 See void awake(void* message=0). More...
 
static void Fl::awake (void *message=0)
 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. More...
 
static int Fl::lock ()
 The lock() method blocks the current thread until it can safely access FLTK widgets and data. More...
 
static void * Fl::thread_message ()
 The thread_message() method returns the last message that was sent from a child by the awake() method. More...
 
static void Fl::unlock ()
 The unlock() method releases the lock that was set using the lock() method. More...
 

Detailed Description

fl multithreading support functions declared in <FL/Fl.H>

Function Documentation

◆ awake() [1/2]

int Fl::awake ( Fl_Awake_Handler  func,
void *  data = 0 
)
static

See void awake(void* message=0).

Let the main thread know an update is pending and have it call a specific function.

Registers a function that will be called by the main thread during the next message handling cycle. Returns 0 if the callback function was registered, and -1 if registration failed. Over a thousand awake callbacks can be registered simultaneously.

See also
Fl::awake(void* message=0)

◆ awake() [2/2]

void Fl::awake ( void *  msg = 0)
static

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.

In the context of a threaded application, a call to Fl::awake() with no argument will trigger event loop handling in the main thread. Since it is not possible to call Fl::flush() from a subsidiary thread, Fl::awake() is the best (and only, really) substitute.

It's not necessary to wrap calls to any form of Fl::awake() by Fl::lock() and Fl::unlock(). Nevertheless, the early, single call to Fl::lock() used to initialize threading support is necessary.

Function Fl::awake() in all its forms is typically called by worker threads, but it can be used safely by the main thread too, as a means to break the event loop.

See also
Multithreading

◆ lock()

int Fl::lock ( )
static

The lock() method blocks the current thread until it can safely access FLTK widgets and data.

Child threads should call this method prior to updating any widgets or accessing data. The main thread must call lock() to initialize the threading support in FLTK. lock() will return non-zero if threading is not available on the platform.

Child threads must call unlock() when they are done accessing FLTK.

When the wait() method is waiting for input or timeouts, child threads are given access to FLTK. Similarly, when the main thread needs to do processing, it will wait until all child threads have called unlock() before processing additional data.

Returns
0 if threading is available on the platform; non-zero otherwise.

See also: Multithreading

◆ thread_message()

void * Fl::thread_message ( )
static

The thread_message() method returns the last message that was sent from a child by the awake() method.

See also: Multithreading

◆ unlock()

void Fl::unlock ( )
static

The unlock() method releases the lock that was set using the lock() method.

Child threads should call this method as soon as they are finished accessing FLTK.

See also: Multithreading