<div dir="ltr">Hi, I am new in RTEMS. I can't understand why the following threaded application is not running on RTEMS as expected. Basically, it creates two pthreads. One fills a buffer and the other one get an slice and submit it to a cluster for processing (typical producer-consumer problem), something like:<div>
<br></div><div>void thread1()</div><div>{</div><div>  while(1)</div><div>  {</div><div>    for (i=0; i < size;i++)</div><div>    {</div><div>      if (buffer[i].st == -1)</div><div>      {</div><div>        pthread_mutex_lock(&mutex); </div>
<div>          genData(buffer[i]);</div><div>          buffer[i].st=0;            // ready to be consumed</div><div>        pthread_mutex_unlock(&mutex);</div><div>      }</div><div>    }</div><div>  }</div><div>}</div>
<div><br></div><div>void thread2()</div><div>{</div><div>  while(1)</div><div>  {</div><div>    // n stores the slice start <br></div><div>    ready = false;</div><div>    while (!ready)                 // it gets a free slice</div>
<div>    {</div><div>      ready = true;</div><div>      for(i=n;i<n+slice;i++)</div><div>        if (buffer[i].st = -1)</div><div>          ready = false; </div><div>     }</div><div>    // process the slice on cluster</div>
<div>   pthread_mutex_lock(&mutex);</div><div>      for (i=n;i<n+slice;i++)</div><div>        buffer[i].st = -1;       // now new data can be inserted on it</div><div><div>   pthread_mutex_unlock(&mutex);</div>
</div><div>  }</div><div>}</div><div><br></div><div>It runs fine on a Linux/GNU system, but not in RTEMS. Under some circumstances the program is blocked. It is like if thread2 was running forever on the second while, and thread1 didn't fill the buffer. Do you have any idea of what is happening? I would expect that each thread would run on parallel on each core.</div>
<div><br></div><div>Thanks.</div></div>