Application based on Pthreads is blocked under RTEMS

Gedare Bloom gedare at rtems.org
Thu Jul 3 01:37:46 UTC 2014


 I'll make one note below, but you should submit the entire
self-contained example that shows the incorrect behavior if you want
debugging help.

On Wed, Jul 2, 2014 at 6:23 AM, smc smc <smc101979 at gmail.com> wrote:
> 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)
If you have this statement with an assignment operator, the
while(!ready) loop should never terminate if slice > 0.

>           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.
>
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users


More information about the users mailing list