All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Strangeness in named Semaphores(xenomai posix skin)
@ 2005-10-21 15:57 Luotao Fu
  2005-10-21 19:39 ` Gilles Chanteperdrix
  2005-10-21 21:38 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 6+ messages in thread
From: Luotao Fu @ 2005-10-21 15:57 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 1439 bytes --]

Hi folks,

I got the feeling, that named semaphores in xenomai posix skin don't
work properly. I hacked some simple code to test this and attached the
code to this mail, so that you might have a look of my problem yourself.

In my code the main thread initialize a named Semaphore, locks it up and
than create a thread. The thread initialize a semaphore with the same
name and than tries to lock it. Since the semaphore is already locked by
the main thread, the thread blocks. As the main thread is waiting for
the finishing of the thread. It blocks too. So at this point the
programm should block. I tried two sem lock call in the thread, in one
it calls simply sem_wait() and blocks till the Implosion of the Universe
or the arrival of SIGINT, in the other it calls a sem_timedwait() and
blocks for 5 seconds. Both variants work just fine as normal posix
binay. Once compiled and linked against the xenomai posix library, the
sem_wait() appears however not to block at all and the trhead just
marchs through. the sem_timedwait() quits with a segfault.

I'm quite not understanding this. Have I overlooked something or is
there evtl. a bug in the posix skin?

P.S.
Systemconfiguration
Kernel: Vanilla 2.6.13 patched with adeos-linux-2.6.13-i386-r13.patch
Distr. Debian 3.1
Testhost: vmware 5.0
compiler gcc 3.3.5
Xenomai: 2.0, the most recent version from svn. (just updated it 15 Min.
ago. :-) )

Thanx a lot in advance
Cheers
Luotao Fu

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 1974 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <pthread.h>
#include <limits.h>
#include <semaphore.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#define THR_AMOUNT 1

char *semName = "/testSem";
struct timespec t;

void *funcA(void *parm){
	sem_t *binSem;
 	if ((binSem = sem_open(semName, O_CREAT)) == SEM_FAILED){
	  	perror("cannot open Semaphore"); 
	  	exit(1);
 	}
	printf("semAdress: %p\n", binSem);
	printf("starting Thread A\n");	
	clock_gettime(CLOCK_REALTIME, &t);
	//while (sem_wait(binSem) == -1 && errno == EINTR)
	//  ;
	t.tv_sec += 5;
	sem_timedwait(binSem, &t);	
	printf("finishing Thread A\n");
 	sem_close(binSem);
	pthread_exit(NULL);
}

int main(int argc, char **argv)
{	
	int co,rc;	
	pthread_t testThread[THR_AMOUNT];
 	pthread_attr_t thrAttr;	
 	struct sched_param param = { .sched_priority = 99 };
	sem_t *binSem;
 	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
 		perror("could not lock memeory\n");
 		exit(1);
 	}
 	if ((binSem = sem_open(semName, O_CREAT)) == SEM_FAILED){
	  	perror("cannot open Semaphore"); 
	  	exit(1);
 	}
	printf("semAdress: %p\n", binSem);
	sem_post(binSem);
 	sem_wait(binSem); 	
	pthread_attr_init(&thrAttr);
 	pthread_attr_setdetachstate(&thrAttr,PTHREAD_CREATE_JOINABLE);
 	pthread_attr_setinheritsched(&thrAttr,PTHREAD_EXPLICIT_SCHED);	
 	pthread_attr_setschedpolicy(&thrAttr,SCHED_FIFO); 
 	pthread_attr_setschedparam(&thrAttr,&param); 
	if ( (rc = pthread_create(&testThread[0],&thrAttr, funcA, NULL))
 	     != 0 ){
 	        fprintf(stderr, "cannot create Threads %s\n", strerror(rc)); 
 		exit(1);
 	}
 	for ( co = 0; co < THR_AMOUNT; co++) {
 		if ( pthread_join(testThread[co], NULL) != 0 ){
 			perror("cannot join Threads");			
 			exit(1);
 		}
 	}
 	if (munlockall() == -1){
 		perror("munlockall failure");
 		exit(1);
 	}
 	sem_close(binSem);
	sem_unlink(semName);
	return 0;
}

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

end of thread, other threads:[~2005-10-22  7:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-21 15:57 [Xenomai-help] Strangeness in named Semaphores(xenomai posix skin) Luotao Fu
2005-10-21 19:39 ` Gilles Chanteperdrix
2005-10-21 21:54   ` Luotao Fu
2005-10-21 21:38 ` Gilles Chanteperdrix
2005-10-21 22:11   ` Luotao Fu
2005-10-22  7:27     ` 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.