Results 1 to 1 of 1
Hi all,
im working with 2 threads currenlty, while both threads are running in one point Both threads need to update a value ( same as counter ) which im ...
- 01-15-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 3
Synchronization of threads
Hi all,
im working with 2 threads currenlty, while both threads are running in one point Both threads need to update a value ( same as counter ) which im using mutix for that, But I need the final counter value to be used in the 2 threads...
Example ( thread 1 and thread 2 reads counter value then do some process then both will update counter then both should read the final counter value then procces)
How do I solve it in a proper why ?
Using Condition signal and wait should be great But both threads are using the same Function Expansion. Cuz as far as i read cond_wait and Cond_signal is placed by different functions.
A temporary solution for 2 threads that i have done shown below but its CPU cycle consuming cuz its using While loop.
// wait for both threads to reach the same point so they can read an updated value from both of them
if ( thread_id == 0 )
while ((t0_round > t1_round) && (t0_round != 0))
{
if (t0_round <= t1_round) break;
}
else
while ((t1_round > t0_round) && (t1_round != 0))
{
if (t1_round <= t0_round) break;
}


Reply With Quote