From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16104 invoked by alias); 31 May 2002 07:48:02 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 16048 invoked from network); 31 May 2002 07:47:57 -0000 Received: from unknown (HELO mail.twc-online.net) (66.8.86.35) by sources.redhat.com with SMTP; 31 May 2002 07:47:57 -0000 Received: from mondriaan.stonethree.com (cache-1.twc-online.net [66.8.86.58]) by mail.twc-online.net (8.11.3/8.11.3) with ESMTP id g4V7m2R27983; Fri, 31 May 2002 09:48:02 +0200 Received: from thor (thor.stonethree.com [192.168.1.12]) by mondriaan.stonethree.com (8.11.0/8.11.0) with SMTP id g4V7lg304962; Fri, 31 May 2002 09:47:47 +0200 Message-ID: <003601c20877$51262520$0c01a8c0@thor> From: "Rob Fanner" To: "Ross Johnson" , "Bossom, John" Cc: References: <430F887D415DD1118C2700805F31ECF106B591B1@sota0005.cognos.com> <3CF70ACF.902@ise.canberra.edu.au> Subject: Re: semaphores Date: Fri, 31 May 2002 00:48:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-SW-Source: 2002/txt/msg00071.txt.bz2 Ross wrote: > Hi John/Rob, > > Bossom, John wrote: > > sem_getvalue()? > > > There's no test in the current test suite for this routine (will do > though). And the routine would seem to need to be rewritten. > > Regards. > Ross Thanks Ross. I've thought of one or two workarounds (which mostly involve using ReleaseSemaphore(semhandle,1,previouscount) followed by a trywait to solve the NT problem of not being able to do a ReleaseSemaphore with a 0 releasecount. However, a more elegant solution --- closer to the original intent --- could be to exploit the following, taken from "Win32 System Programming Second Edition" by Johnson M Hart, chapter 9, page 256 : "The release count must be greater than zero, but if it would cause the semaphore count to exceed the maximum, the call will fail, returning FALSE, and the count will remain unchanged. Releasing a semaphore with a large count is a method used to obtain the current count atomically (of course, another thread might change the value immediately)." So instead of if ( ReleaseSemaphore( (*sem)->sem, 0L, &value) ) { *sval = value; } this might be a good alternative if ( ReleaseSemaphore( (*sem)->sem, GREATER_THAN_MAXIMUM_SEM_VALUE, &value) ) { *sval = value; } Sorry that I've not hacked this into the source and sent you a correct patch, but I'm still not confident with VC++ builds, and I'm still a bit clueless as to how to set up a pthreadVCE.lib (which I need) as opposed to a pthreadVC.lib (the standard build for the distro's .dsp file). OK. Thanks again for all the advice. It is really appreciated. Rob