From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,URI_HEX autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e53617e6821a1c7e,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-29 15:04:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!212.97.175.23!not-for-mail From: Jano Newsgroups: comp.lang.ada Subject: Suspicious reentrant semaphore Date: Wed, 30 Apr 2003 00:04:23 +0200 Message-ID: NNTP-Posting-Host: 212.97.175.23 X-Trace: fu-berlin.de 1051653859 12329213 212.97.175.23 (16 [49872]) X-Newsreader: MicroPlanet Gravity v2.50 Xref: archiver1.google.com comp.lang.ada:36748 Date: 2003-04-30T00:04:23+02:00 List-Id: Hello everybody, 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. Here are the spec and body: P.s: I can guarantee that never use it without the controlled object, so no calls to V should occur without a previous P. P.s: If it turns out that this isn't the culprit, I will amuse you ;-) with more samples of my code ^_^ Thanks! ------------SPEC--------------------------------------------------- package Adagio.Monitor is use Ada.Task_identification; protected type Semaphore is entry P (Owner : Task_id); entry V; private Caller : Task_id := Null_task_id; -- Requester In_use : Natural := 0; -- Times requested end Semaphore; type Semaphore_access is access all Semaphore; -- Use: -- S : aliased Semaphore; -- M : Object (S'access); type Object (S : access Semaphore) is new Finalization.Limited_Controlled with null record; procedure Initialize (this : in out Object); procedure Finalize (this : in out Object); end Adagio.Monitor; ---------------------BODY---------------------------------- package body Adagio.Monitor is protected body Semaphore is entry P (Owner: Task_id) when In_use = 0 or else Current_task = Caller is begin Caller := Owner; In_use := In_use + 1; end P; entry V when In_use > 0 and Current_task = Caller is begin In_use := In_use - 1; end V; end Semaphore; -- Get procedure Initialize (this : in out Object) is begin this.S.P (Current_task); end Initialize; -- Release procedure Finalize (this : in out Object) is begin this.S.V; end Finalize; end Adagio.Monitor; -- ------------------------- Jano 402450.at.cepsz.unizar.es -------------------------