GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Apr-2009, 16:16
nharder nharder is offline
New Member
 
Join Date: Apr 2009
Posts: 2
nharder is on a distinguished road

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  
Old 15-May-2009, 14:13
nharder nharder is offline
New Member
 
Join Date: Apr 2009
Posts: 2
nharder is on a distinguished road

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 GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:23.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.