Date: Thu, 29 Sep 2005 20:47:09 +0800 From: "Gary Li-126" <liguoqiang_0121@126.com> To: <freebsd-stable@freebsd.org> Subject: Problem About how to use shared posix semaphore Message-ID: <001701c5c4f3$e82ac020$c700a8c0@lgq>
next in thread | raw e-mail | index | archive | help
Hi,
I always get the error message:"Operation not permitted" When I use sem_init set pshared argument equal 1. Compiling as : "gcc -o sem_test sem_test.c -lc_r". My freebsd ver is release 5.4 p6.
Test code appear below:
1 #include <sys/types.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <pthread.h>
9 #include <semaphore.h>
10
11 int main(int argc, char ** argv)
12 {
13 sem_t mutex;
14 if (-1 == sem_init (&mutex, 1, 1)) {
15 printf("sem init error:%s\n", strerror(errno));
16 exit(0);
17 }
18 sem_wait (&mutex);
19 printf("sem wait ok:\n");
20 sem_post (&mutex);
21 sem_destroy (&mutex);
22 return 0;
23 }
Best regards,
Gary Li
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001701c5c4f3$e82ac020$c700a8c0>
