All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [Xenomai-help] pthread_mutex_destroy in 2.2 rc2
@ 2006-07-02 13:43 Landau, Bracha
  2006-07-02 15:35 ` Gilles Chanteperdrix
  2006-07-03 13:15 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 6+ messages in thread
From: Landau, Bracha @ 2006-07-02 13:43 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai

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:gilles.chanteperdrix@xenomai.org]
Sent: Thursday, June 29, 2006 7:17 PM
To: Landau, Bracha
Cc: xenomai@xenomai.org
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 postmaster@domain.hid and destroy the original message.
***********************************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: [Xenomai-help] pthread_mutex_destroy in 2.2 rc2
@ 2006-07-03 15:26 Landau, Bracha
  0 siblings, 0 replies; 6+ messages in thread
From: Landau, Bracha @ 2006-07-03 15:26 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai

The patch works, thanks.

-----Original Message-----
From: Gilles Chanteperdrix [mailto:gilles.chanteperdrix@xenomai.org]
Sent: Monday, July 03, 2006 4:15 PM
To: Landau, Bracha
Cc: xenomai@xenomai.org
Subject: RE: [Xenomai-help] pthread_mutex_destroy in 2.2 rc2


Landau, Bracha wrote:
 > 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.)

Thanks for the piece of code. The error was due to a missing
initialization, that got unseen under simulation because simulator
allocated memory was always zero. It is now fixed in the repository. You
can apply the attached patch to 2.2 rc3 to fix it.

-- 


					    Gilles Chanteperdrix.

*** NDS IL IT scanned this email for malicious content ***
*** IMPORTANT: Do not open attachments from unrecognized senders  ***
***********************************************************************************
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 postmaster@domain.hid and destroy the original message.
***********************************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Xenomai-help] pthread_mutex_destroy in 2.2 rc2
@ 2006-06-29 15:36 Landau, Bracha
  2006-06-29 16:16 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 6+ messages in thread
From: Landau, Bracha @ 2006-06-29 15:36 UTC (permalink / raw)
  To: xenomai

I'm using Xenomai 2.2 rc2 on an MPC8247 board.
When I try to destroy a mutex I get error x10 (EBUSY).
The mutex is not locked. When I run the same code with the regular pthreads library the function does not return an error.
Is this a Xenomai bug?


***********************************************************************************
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 postmaster@domain.hid and destroy the original message.
***********************************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-07-03 15:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-02 13:43 [Xenomai-help] pthread_mutex_destroy in 2.2 rc2 Landau, Bracha
2006-07-02 15:35 ` Gilles Chanteperdrix
2006-07-03 13:15 ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2006-07-03 15:26 Landau, Bracha
2006-06-29 15:36 Landau, Bracha
2006-06-29 16:16 ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.