From: Luotao Fu <devtty0@domain.hid>
To: xenomai@xenomai.org
Subject: [Xenomai-help] Strangeness in named Semaphores(xenomai posix skin)
Date: Fri, 21 Oct 2005 17:57:05 +0200 [thread overview]
Message-ID: <43590FD1.5030503@domain.hid> (raw)
[-- 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,¶m);
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;
}
next reply other threads:[~2005-10-21 15:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-21 15:57 Luotao Fu [this message]
2005-10-21 19:39 ` [Xenomai-help] Strangeness in named Semaphores(xenomai posix skin) 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43590FD1.5030503@domain.hid \
--to=devtty0@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.