|
|
Message-ID: <20150301173048.GD16260@port70.net>
Date: Sun, 1 Mar 2015 18:30:49 +0100
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: semaphore redesign
* Alexander Monakov <amonakov@...ras.ru> [2015-02-28 02:21:22 +0300]:
> int sem_post(sem_t *sem)
> {
> int val;
> do {
> val = sem->__val[0];
> if (val == SEM_VALUE_MAX) {
> errno = EOVERFLOW;
> return -1;
as discussed on irc early return here without a barrier is not ok
(it is a hard to observe corner case, i add the comment here so
it does not get forgotten)
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
> }
> } while (val != a_cas(sem->__val, val, val+1));
> if (val < 0) {
> int priv = sem->__val[2];
> a_inc(sem->__val+1);
> __wake(sem->__val+1, 1, priv);
> }
> return 0;
> }
>
> int sem_trywait(sem_t *sem)
> {
> int val;
> do {
> val = sem->__val[0];
> if (val <= 0) {
> errno = EAGAIN;
> return -1;
likewise
> }
> } while (val != a_cas(sem->__val, val, val-1));
> return 0;
> }
>
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.