pthread's mutex question

Joel Sherrill joel.sherrill at OARcorp.com
Tue Apr 30 02:26:52 UTC 2002



Pattara Kiatisevi wrote:
> 
> Hi again,
> 
> I have played with pthread's mutex with this small code:
> 
>   pthread_mutex_t a,b;
> 
>   printf("Initialize mutexes...\n");
>   pthread_mutex_init(&a, NULL);
>   pthread_mutex_init(&b, NULL);
> 
>   printf("Trying to lock mutex a..\n");
>   pthread_mutex_lock(&a);
>   printf("Got mutex a..\n");
> 
>   printf("Trying to lock mutex a..\n");
>   pthread_mutex_lock(&a);       <----------should block here
>   printf("Got mutex a..\n");
> 
>   fprintf(stderr,"Done.\n");
> 
> On Linux, the program will block forever at the second attempt to lock
> mutex a but on RTEMS it doesn't block. Instead it returns with value 45.
> Is there any chance to have it blocked here in RTEMS?

That's EDEADLOCK which probably means you are attempting to acquire
a mutex you already own.

Also ... What target and BSP are you using?  If accidentally
using unix/posix that is an impact since RTEMS POSIX API
can't be used there.

> Regards,
> Pattara
> 
> --
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.fsf.org/philosophy/no-word-attachments.html
> ----------------------------------------------------------------------
> Ott Pattara Kiatisevi                              T L W G
> M.Sc. INFOTECH Student, Stuttgart, Germany      http://linux.thai.net/
> ----------------------------------------------------------------------

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985



More information about the users mailing list