c++ - The execution sequence after conditional variable notify -


there 2 threads (call them t1 , t2) sync each other boost condition variable , mutex like:

boost::condition_variable global_cond; boost::mutex global_mutex; boost::unique_lock<boost::mutex> lock( global_mutex);  thread1() {   global_cond.notify_one();   code_block_a(); }  tread2() {   global_cond.wait(lock)   code_block_b(); } 

let's can gugarntee thread2 come wait first , thread1 notify.

my question is, determinastic code_block_a() or code_block_b() execute first?

not guaranteed. system may perform context switching right after thread1 called notify_one() , allow thread2() run. , may not.

please note code buggy because global_cond.wait(lock) can spuriously woken , tread2 can run code_block_b() before thread1() has run.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -