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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.157.6.11 with SMTP id 11mr7190785otn.7.1472321194410; Sat, 27 Aug 2016 11:06:34 -0700 (PDT) X-Received: by 10.157.44.69 with SMTP id f63mr705032otb.2.1472321194382; Sat, 27 Aug 2016 11:06:34 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!j128no465575ith.0!news-out.google.com!d68ni40860ith.0!nntp.google.com!j128no465564ith.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 27 Aug 2016 11:06:34 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.250.26.106; posting-account=3pYsyQoAAACcI-ym7XtMOI2PDU8gRZS5 NNTP-Posting-Host: 50.250.26.106 References: <35ae841e-5947-44e9-a8d4-479cf40c4277@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <37d2b3b6-5d23-421e-b583-70d23fec2abb@googlegroups.com> Subject: Re: How to simulate semaphores with Ada's tasks? From: Andrew Shvets Injection-Date: Sat, 27 Aug 2016 18:06:34 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:31603 Date: 2016-08-27T11:06:34-07:00 List-Id: On Thursday, August 25, 2016 at 3:39:50 AM UTC-4, Dmitry A. Kazakov wrote: > On 25/08/2016 02:41, Andrew Shvets wrote: > > From what I've read, tasks do not have semaphores that can permit it > > to lock a piece of memory and prevent it from being accessed, is this > > correct? >=20 > It is unclear what you mean here. Semaphore blocks a resource, not=20 > necessarily memory. Technically you cannot block memory at the language= =20 > level, e.g. using memory management registers. It is too low-level. So=20 > it is operations that are blocked with memory encapsulated somewhere=20 > into an object or a package. >=20 > > If so, then the best possible way to simulate this is to have tasks > > send messages to one another and synchronize when something is > > locked/unlocked. >=20 > That is called "monitor". It can be used to implement the semaphore too,= =20 > but nobody does that. In most cases monitor is better than semaphore=20 > when that comes in question. >=20 > Semaphore has little if no use when k>1. Only mutex (semaphore k=3D1) is= =20 > actively used. >=20 > > Is there a better approach? >=20 > Sometimes monitor is better sometimes mutex is. >=20 > Regarding mutex what kind of are you looking for? Plain? Reentrant?=20 > Read-write mutex? Arrays of mutexes? >=20 > In Ada synchronization objects like mutex are implemented using=20 > protected object. A plain mutex or semaphore is trivial to implement. >=20 > --=20 > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de Hello Dmitry, Yes, resources is a better term. What I'm looking for -- well, still learn= ing about it, I'm quite new to this -- is really to learn more about mutexe= s. I think I got my terminologies mixed up. What I really meant is a mute= x, not a semaphore (I want to be able to lock down a resource so that only = one task has access to it at a time.) A plain mutex is something that I'd like to start off with. Thanks for you= r help, but for now I'd like to figure things out on my own, if I hit a wal= l I will post here.