LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I call a common function from four different threads?

I've developed a TCP client/server application where four different clients talk to one sever.  The client application was modified from the tcp\client.cws sample, and the server was modified from the tcp\MultiClientServer.cws sample.  In my application, the server controls something that the four clients must share.  So, from the MultiClientServer example, I have four separate threads handling the requests from the clients, but after the individual threads interpret the requests, the threads will have to call a common function to apply the requests. 
 
Should the common function be in the main thread?  How do I do this call?  With PostDeferredCall?  Or, just call the common function from each of the threads? 
 
Should I create a fifth thread which the common function runs in?  If so, how do I call it?  With PostDeferredCallToThread (if the common function is in the fifth thread)?
 
 
0 Kudos
Message 1 of 2
(2,816 Views)
There's more than one way to do this, depending in particular if the
function is shared by the threads or not:
- direct call from each thread (separate environment)
- PostDeferedCall from each thread will avoid environment overlap but keep
separate threads.
- PostDeferedCallToThread for that the function can have a common
environment, never mind which thread calls it. Maybe add a mutex in it.
- ...
--
Guillaume Dargaud
http://www.gdargaud.net/
"Science is merely an extremely powerful method of winnowing what's true
from what feels good." - Carl Sagan.


0 Kudos
Message 2 of 2
(2,788 Views)