Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Sep 2005 14:27:32 +0100
From:      Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To:        Gary Li-126 <liguoqiang_0121@126.com>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: Problem About how to use shared posix semaphore
Message-ID:  <1128000452.44550.8.camel@buffy.york.ac.uk>
In-Reply-To: <001701c5c4f3$e82ac020$c700a8c0@lgq>
References:  <001701c5c4f3$e82ac020$c700a8c0@lgq>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 2005-09-29 at 20:47 +0800, Gary Li-126 wrote:
> 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.

>From sem_init(3):

A non-zero value for pshared specifies a
shared semaphore that can be used by multiple processes, which this
implementation is not capable of.

I suspect you're asking the impossible.  You could try using a different
threading library, but libc_r won't work:

/usr/src/lib/libc_r/uthread/uthread_sem.c:

_sem_init(sem_t *sem, int pshared, unsigned int value)
{
 [...]
        if (pshared != 0) {
                /*
                 * The user wants a semaphore that can be shared among
                 * processes, which this implementation can't do.  Sounds like a
                 * permissions problem to me (yeah right).
                 */
                errno = EPERM;
                retval = -1;
                goto RETURN;
        }

This return code is documenbted in the sem_init man page:

[EPERM]            Unable to initialize a shared semaphore.

Gavin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1128000452.44550.8.camel>