Application based on Pthreads is blocked under RTEMS

smc smc smc101979 at gmail.com
Wed Jul 2 10:23:48 UTC 2014


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:

void thread1()
{
  while(1)
  {
    for (i=0; i < size;i++)
    {
      if (buffer[i].st == -1)
      {
        pthread_mutex_lock(&mutex);
          genData(buffer[i]);
          buffer[i].st=0;            // ready to be consumed
        pthread_mutex_unlock(&mutex);
      }
    }
  }
}

void thread2()
{
  while(1)
  {
    // n stores the slice start
    ready = false;
    while (!ready)                 // it gets a free slice
    {
      ready = true;
      for(i=n;i<n+slice;i++)
        if (buffer[i].st = -1)
          ready = false;
     }
    // process the slice on cluster
   pthread_mutex_lock(&mutex);
      for (i=n;i<n+slice;i++)
        buffer[i].st = -1;       // now new data can be inserted on it
   pthread_mutex_unlock(&mutex);
  }
}

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.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20140702/c6609bbe/attachment.html>


More information about the users mailing list