comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Suspicious reentrant semaphore
Date: Wed, 30 Apr 2003 10:06:06 +0200
Date: 2003-04-30T10:06:06+02:00	[thread overview]
Message-ID: <b8o01n$bh20l$1@ID-77047.news.dfncis.de> (raw)
In-Reply-To: MPG.19191554aff631919896ed@News.CIS.DFN.DE

Jano wrote:

> I'm developing a multitasking program that runs OK for several hours. At
> some indeterminate moment, a bunch of its tasks cease to respond, and I
> have a strong suspicion that the culprit is a semaphore package I've
> done.
> 
> The purpose is to have a semaphore which can be called more than a time
> _by the same task_, and that must be released the same amount of times.
> Nested calls, simply.
> 
> Leaving aside why I have done that (yes, poor design, I'm removing it
> anyway ;-), I would like to know if my package is right or really is
> there some race condition. Please comment on it. I know that
> Current_Task shouldn't be called inside entries (in fact Gnat doesn't
> allow it, I tried :-P) but doesn't complain about it being used in
> barriers. Anyways, I have a (maybe wrong) feel about that being related
> to the deadlock.

The requeue statement does the trick in case you want to use a parameter 
value in a barrier. You could add one more private entry and requeue to it 
if the task is not the owner:

entry P (Owner: Task_id) when True is
begin
   if Caller = Owner then
      In_use := In_use + 1;
   else
      requeue Alien_P with abort;
   end if;
end P;

entry Alien_P (Owner: Task_id) when In_use = 0 is
begin
   Caller := Owner;
   In_use := 1;
end Alien_P;

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-04-30  8:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-29 22:04 Suspicious reentrant semaphore Jano
2003-04-30  8:06 ` Dmitry A. Kazakov [this message]
2003-05-01 12:33   ` Jano
2003-05-02  7:28     ` Dmitry A. Kazakov
2003-05-02 11:24       ` Jano
2003-05-02 20:29         ` tmoran
2003-05-05 11:24       ` Michal Morawski
2003-05-05 17:42         ` Simon Wright
2003-05-05 18:03         ` Jano
2003-05-05 20:18           ` Micha� Morawski
2003-04-30 13:07 ` Ian Broster
2003-05-01 12:33   ` Jano
2003-04-30 17:39 ` Randy Brukardt
2003-04-30 23:21   ` Peter Richtmyer
2003-05-01  4:59     ` Simon Wright
2003-05-01 12:46   ` Jano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox