Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your barrier implementation does not work, at least not if the barrier will be used more than once. Consider this case:</p> <ol> <li><code>NUM_OF_THREADS-1</code> threads are waiting at the barrier, spinning.</li> <li>Last thread arrives and passes through the barrier.</li> <li>Last thread exits barrier, continues processing, finishes its next task, and reenters the barrier wait.</li> <li>Only now do the other waiting threads get scheduled, and they can't exit the barrier because the counter was incremented again. Deadlock.</li> </ol> <p>In addition, one often-overlooked but nasty issue to deal with using dynamically allocated barriers is destroying/freeing them. You'd like any one of the threads to be able to perform the destroy/free after the barrier wait returns as long as you know nobody will be trying to wait on it again, but this requires making sure <strong>all waiters</strong> have finished touching memory in the barrier object before <strong>any waiters</strong> wake up - not an easy problem to solve. See my past questions on implementing barriers...</p> <p><a href="https://stackoverflow.com/questions/5886614/how-can-barriers-be-destroyable-as-soon-as-pthread-barrier-wait-returns">How can barriers be destroyable as soon as pthread_barrier_wait returns?</a></p> <p><a href="https://stackoverflow.com/questions/6935769/can-a-correct-fail-safe-process-shared-barrier-be-implemented-on-linux">Can a correct fail-safe process-shared barrier be implemented on Linux?</a></p> <p>And unless you know you have a special-case where none of the difficult problems apply, don't try implementing your own for an application.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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