From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7109 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: semaphore redesign Date: Sun, 1 Mar 2015 18:30:49 +0100 Message-ID: <20150301173048.GD16260@port70.net> References: <1409123141.4476.18.camel@eris.loria.fr> <20140827074310.GK12888@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1425231069 11519 80.91.229.3 (1 Mar 2015 17:31:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Mar 2015 17:31:09 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7122-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 01 18:31:08 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YS7hs-0004LL-Bb for gllmg-musl@m.gmane.org; Sun, 01 Mar 2015 18:31:08 +0100 Original-Received: (qmail 1459 invoked by uid 550); 1 Mar 2015 17:31:06 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 1395 invoked from network); 1 Mar 2015 17:31:01 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:7109 Archived-At: * Alexander Monakov [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; > } >