As you suggested, I've upgraded to xenomai 2.2 rc3.
I still see the same phenomenon.
I'm attaching code that will reproduce the error.
(When you ^c out of the main loop, the pthread_cleanup_pop is called, and the 
call to pthread_mutex_destroy returns 0x10.)

//********************************************************************
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/select.h>
#include <error.h>
#include <errno.h>

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>

#include <sys/time.h>
#include <sys/ioctl.h>
#include <netdb.h>
#include <pthread.h>
#include <unistd.h>
#include <mqueue.h>
#include <sys/mman.h>
pthread_t Main_Exec_thread_id;

#define DPRINT(arg) printf arg

pthread_mutex_t testmutex;


#define MAIN_TASK_PRI 1
#define MAIN_STACK_SIZE 8192


pthread_attr_t Main_Exec_attr;
struct sched_param Main_Exec_parm;

int Main_PID;

void shut_down (void *par)
{
        printf ("shutting down, pid = %08x\n", getpid()) ;

        int res = pthread_mutex_destroy (&testmutex);

        printf ("pthread_mutex_destroy returned %08x\n", res) ;

        printf ("MAIN EXEC THREAD EXITING!\n") ;



}


void error_exit (int sval)
{
  void *val;
  DPRINT( ("error_exit, pid = %08x, signal = %08x\n", getpid (), sval));
  if (getpid () == Main_PID)
  {
        printf ("cancelling main thread\n");
        pthread_cancel (Main_Exec_thread_id); 
        printf ("waiting for main thread to exit\n");
        pthread_join (Main_Exec_thread_id, &val);
        printf ("exiting\n") ;
  }
}


void *MainExecThread (void *dummy)
{

        printf ("Main Exec Thread starting, pid = %08x\n", getpid()) ;

        pthread_cleanup_push ((void(*)(void*))shut_down, NULL);

        pthread_mutexattr_t attrib;
        int status = pthread_mutexattr_init (&attrib);
        if (status != 0)
                DPRINT( ("pthread_mutexattr_init error\n"));
        status = pthread_mutex_init (&testmutex, &attrib);
        if (status != 0)
                DPRINT( ("pthread_mutex_init error\n") );

        
        pause ();

        DPRINT( ("MAIN EXEC PAUSE RETURNED\n") );
        pthread_cleanup_pop (true);
        return 0;
}

int main (int argc, char *argv[])
{

        Main_PID = getpid ();
        printf ("main pid = %08x\n", Main_PID) ;

        signal (SIGINT, error_exit);
        signal (SIGQUIT, error_exit);
        signal (SIGHUP, error_exit);
        signal (SIGTERM, error_exit);

        mlockall (MCL_CURRENT | MCL_FUTURE);

        pthread_attr_init (&Main_Exec_attr);

        pthread_attr_setinheritsched(&Main_Exec_attr, 1);
        pthread_attr_setschedpolicy(&Main_Exec_attr, SCHED_FIFO);
        pthread_attr_setstacksize(&Main_Exec_attr, MAIN_STACK_SIZE);
        Main_Exec_parm.sched_priority = MAIN_TASK_PRI;
        pthread_attr_setschedparam(&Main_Exec_attr, &Main_Exec_parm);

        pthread_create (&Main_Exec_thread_id, &Main_Exec_attr, 
(void*(*)(void*))MainExecThread, 0); 

        pause ();

        DPRINT( ("MAIN PAUSE RETURNED\n") );

        exit (0);
        
-----Original Message-----
From: Gilles Chanteperdrix [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 29, 2006 7:17 PM
To: Landau, Bracha
Cc: [email protected]
Subject: Re: [Xenomai-help] pthread_mutex_destroy in 2.2 rc2


Landau, Bracha wrote:
 > I'm using Xenomai 2.2 rc2 on an MPC8247 board.

You should be using 2.2 rc3, it implements per-process cleanup, so even
if pthread_mutex_destroy fails, if the mutex is not shared between
several processes, it will automatically be destroyed when the
application terminates.

 > When I try to destroy a mutex I get error x10 (EBUSY).
 > The mutex is not locked. 

EBUSY is also returned if the mutex is currently "bound" to a condition
variable, that is, if some thread is currently blocked in a call to
pthread_cond_wait using the mutex as second argument. In this case, the
application is expected to cancel the thread blocked in the call to
pthread_cond_wait, the said thread is expected to have
pthread_cleanup_pushed a cleanup function unlocking the mutex. Only then
the application can destroy the mutex with pthread_mutex_destroy.

When I run the same code with the regular pthreads library the function does 
not return an error.
 > Is this a Xenomai bug?

Maybe, maybe not. Could you provide a small program showing the bug ?

-- 


                                            Gilles Chanteperdrix.
***********************************************************************************
This email message and any attachments thereto are intended only for use by the 
addressee(s) named above, and may contain legally privileged and/or 
confidential information. If the reader of this message is not the intended 
recipient, or the employee or agent responsible to deliver it to the intended 
recipient, you are hereby notified that any dissemination, distribution or 
copying of this communication is strictly prohibited. If you have received this 
communication in error, please immediately notify the [EMAIL PROTECTED] and 
destroy the original message.
***********************************************************************************

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to