multithreading - Thread synchronisation -



multithreading - Thread synchronisation -

we have 2 methods

a(){ ....//a-method body } b(){ ....//b-method body }

task synchronize them in such way: in order of starting threads method should wait until method b finished. assume have standard synchronisation objects - mutex,semphore,monitor. how can implemented? update 1 i've tried this.

mutex mut = new mutex(); a(){ mut.lock(); ....//a-method body mut.release(); } b(){ mut.lock(); ....//b-method body mut.release(); }

but problem in such implementation there posibility method b executed first. want a wait till b finished

your task accomplished events or semaphores. semaphore created externally threads , b, b sets semaphore @ end, , waits semaphore signal.

if don't need/want utilize synchronization primitives, plenty utilize global boolean variable , check in loop in thread (but of course of study not effective synchro object).

multithreading synchronization

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -