![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Can I call Fl::lock() and Fl::unlock() from the Main Thread?If I write a function that will be called both from the Main Thread and from child threads (created using fl_create_thread()), will it be a problem for the Main Thread if there are calls to Fl::lock() and Fl::unlock() in it?
That is, can I call Fl::lock() from the Main Thread, with an equivalent number of Fl::unlock() calls, and not compromise my thread safety? If I should not call Fl::lock() from the Main Thread, then is there a way to determine if a thread is the Main Thread or not?? Thanks, any info appreciated! |
|||
|
#2
|
|||
|
|||
Re: Can I call Fl::lock() and Fl::unlock() from the Main Thread?Ah, answered my own questions:
1. The Fl::lock() is "recursive" which means it can be called from the main thread as long as the same piece of code does an equivalent number of FL::unlock() calls before returning to the FLTK main loop. 2. You can find out if you are the main thread by calling fltk::in_main_thread(). This call must be protected by calls to Fl::lock and Fl::unlock. Happy Threading!!! ps- now that I have been playing with multi-threaded fltk i have quickly found that the FLTK provided threading doesn't give you much. I recommend using pthreads to get the added functionality in a cross-platform way. |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The