Note that there are some explanatory texts on larger screens.

plurals
  1. POthreads in pthread stop working after some iterations
    primarykey
    data
    text
    <p>I'm trying to write a multi-threaded code but I'm having a little problem. In my program, I have two types of threads, explorers (which i have 4 or 5 of) and main (which I have one of). I want to all explorers threads run simultaneously, and when they're all done main thread starts its job. there's a loop which i do above thing over and over. because of overhead of thread creating i decided to make explorers threads sleep while main is running and wake it when it's done (and of course vise versa ). In order to achieve this goal I used barriers. following is a pseudo-code of my threads:</p> <p>main thread function:</p> <pre><code>void* main(void* arg) { while(true) { wait_for_barrier_1 do_your_job reset_barrier_1 wait_for_barrier_2 } } </code></pre> <p>explorers thread function</p> <pre><code>void* explorers(void* arg) { while(true) { do_your_job wait_for_barrier_1 if(thread_id == 0) { reset_barrier_2 } wait_for_barrier_2 } } </code></pre> <p>barrier_1 is used for preventing main run before ending explorers, and barrier_2 is used for preventing explorers before ending main.</p> <p>My problem is this code don't work fully correct. At the beginning it works fine, but after two or three iteration some of explorer threads suddenly will stop working and so the whole program will stop working.</p> <p>I can't figure it out, specially because there is no rule in number of iteration. In some runs it stops after first iteration, In some other it works fine until 5th or 6th one. </p> <p>By the way i'm using Mac OSX.</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. 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