Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Jun 2009 17:48:07 +0200
From:      cpghost <cpghost@cordula.ws>
To:        Vlad Galu <dudu@dudu.ro>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: Unnamed POSIX shared semaphores
Message-ID:  <20090601154807.GB6065@phenom.cordula.ws>
In-Reply-To: <ad79ad6b0906010833y20042080td1ebe0d3bfffbdc5@mail.gmail.com>
References:  <ad79ad6b0906010833y20042080td1ebe0d3bfffbdc5@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jun 01, 2009 at 06:33:42PM +0300, Vlad Galu wrote:
> Hello,
> 
> According to sem_init(3), we can't have shared unnamed semaphores.
> However, the following code snippet seems to work just  fine:
> 
> -- cut here --
>         sem_t semaphore;
>         if (sem_init(&semaphore, 1, 10) < 0)
>                 std::cout << "Couldn't init semaphore: " <<
> strerror(errno) << std::endl;
>         if (sem_wait(&semaphore) < 0)
>                 std::cout << "Couldn't decrement semaphore: " <<
> strerror(errno) << std::endl;
>         int val;
>         sem_getvalue(&semaphore, &val);
>         std::cout << "Value is " << val << std::endl;
> -- and here --
> 
> Is this a case where sem_init() silently reports success, or should be
> the man page get an update?

You may want to read the comments in /usr/src/lib/libc/gen/sem.c
regarding sem_init().

But yes, the man page is somewhat unclear and I'm not sure the last
paragraph is still totally accurate.

> Thanks,
> Vlad

-cpghost.

-- 
Cordula's Web. http://www.cordula.ws/



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