Note that there are some explanatory texts on larger screens.

plurals
  1. POperformance of boost::threads notify_one vs notify_all
    primarykey
    data
    text
    <p>I have an implementation of Semaphore to manage a shared resource using boost::threads. My implementation of the Semaphore is as shown below.</p> <pre><code>void releaseResource() { boost::unique_lock&lt;boost::mutex&gt; lock(mutex_); boost::thread::id curr_thread = boost::this_thread::get_id(); // scan through to identify the current thread for (unsigned int i=0; i&lt;org_count;++i) { if (res_data[i].thread_id == curr_thread) { res_data[i].thread_id = boost::thread::id(); res_data[i].available = true; break; } } ++count_; condition_.notify_one(); } unsigned int acquireResource() { boost::unique_lock&lt;boost::mutex&gt; lock(mutex_); while(count_ == 0) { // put thread to sleep until resource becomes available condition_.wait(lock); } --count_; // Scan through the resource list and hand a index for the resource unsigned int res_ctr; for (unsigned int i=0; i&lt;org_count;++i) { if (res_data[i].available) { res_data[i].thread_id = boost::this_thread::get_id(); res_data[i].available = false; res_ctr = i; break; } } return res_ctr; } </code></pre> <p>My question is regarding the performance degradation that I notice when there are more threads than the number of resources available. If I use <code>notify_all</code> to wake threads up instead of <code>notify_one</code> as shown in the <code>releaseResource()</code> code, I see that the performance improves. Has anyone else experienced something similar?</p> <p>I am using <strong>Windows 7</strong> and <strong>boost 1.52</strong>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload