LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading and flags

Hi,
I would like to ask a question regarding passing flags between a few threadings running in parallel.
For example, I have thread A, B, C and D running. Thread A is responsible for flagging a flag which causes a particular function in thread B, C and D to activate. So what I am interested to know is that a better way to pass flags between threads rather than declaring that flag as a global variable?
The execution of that function in thread B, C and D has to be simultanous.

Regards,
YB
0 Kudos
Message 1 of 2
(2,843 Views)
I think declaring a flag as a global variable is correct because your flag is just use tu trig something, but if for example you use a counter that several thread increment ou decrement  you may have unexpected comportement.
In this case you should use a mutex or a critical section to make modification on your global variable.
 
In fact, the better thing to trig action between thread is to use event. (CreateEvent, SetEvent, PulseEvent, WaitForSingleObject...)
Jérôme
 
0 Kudos
Message 2 of 2
(2,804 Views)