From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7110 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:50:11 +0100 Message-ID: <20150301175009.GE16260@port70.net> References: <20140827074310.GK12888@brightrain.aerifal.cx> <20150301173048.GD16260@port70.net> 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 1425232242 31008 80.91.229.3 (1 Mar 2015 17:50:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Mar 2015 17:50:42 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7123-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 01 18:50:31 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 1YS80b-000231-Gb for gllmg-musl@m.gmane.org; Sun, 01 Mar 2015 18:50:29 +0100 Original-Received: (qmail 22163 invoked by uid 550); 1 Mar 2015 17:50:27 -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 22091 invoked from network); 1 Mar 2015 17:50:23 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <20150301173048.GD16260@port70.net> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:7110 Archived-At: * Szabolcs Nagy [2015-03-01 18:30:49 +0100]: > * 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 > 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; > > } > >