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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,770f689069566e46,start X-Google-Attributes: gid103376,public From: Magnus Therning Subject: protected types and functions in Ada95 (Newbie) Date: 1997/04/24 Message-ID: <335F2DF6.827@und.ida.liu.se>#1/1 X-Deja-AN: 237010927 Organization: Dept. of Computer and Information Science, Linkoping University Newsgroups: comp.lang.ada Date: 1997-04-24T00:00:00+00:00 List-Id: I want to seize a semaphore in a function. Is that possible using the following protected type semaphore? Functions can only take 'in' parameters, but I need 'in out' since Seize changes the semaphore. package Semaphore_S is type Kind(Num : Integer := 1) is limited private; procedure Seize(Sem : in out Kind); procedure Release(Sem : in out Kind); private protected type Kind(Num : Integer := 1) is entry Secure; procedure Release; private Count : Integer := Num; end Kind; end Semaphore_S; package body Semaphore_S is protected body Kind is Entry Secure when Count > 0 is begin Count := Count - 1; end Secure; procedure Release is begin Count := Count + 1; end Release; end Kind; procedure Seize(Sem : in out Kind) is begin Sem.Secure; end Seize; procedure Release(Sem : in out Kind) is begin Sem.Release; end Release; end Semaphore_S; -- Magnus Therning ( d94magth@und.ida.liu.se ) http://www-und.ida.liu.se/~d94magth/