Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150301175009.GE16260@port70.net>
Date: Sun, 1 Mar 2015 18:50:11 +0100
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: semaphore redesign

* Szabolcs Nagy <nsz@...t70.net> [2015-03-01 18:30:49 +0100]:
> * 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
> 

sorry

the code is ok (applications cannot rely on the barrier in case of
failure), it can lead to surprising results if the application
uses relaxed atomics, but it's not a conformance issue

> > 		}
> > 	} 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.