comp.lang.ada
 help / color / mirror / Atom feed
From: Andrew Shvets <andrew.shvets@gmail.com>
Subject: Re: How to simulate semaphores with Ada's tasks?
Date: Sat, 27 Aug 2016 11:06:34 -0700 (PDT)
Date: 2016-08-27T11:06:34-07:00	[thread overview]
Message-ID: <37d2b3b6-5d23-421e-b583-70d23fec2abb@googlegroups.com> (raw)
In-Reply-To: <npm7c0$fme$1@gioia.aioe.org>

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?
> 
> It is unclear what you mean here. Semaphore blocks a resource, not 
> necessarily memory. Technically you cannot block memory at the language 
> level, e.g. using memory management registers. It is too low-level. So 
> it is operations that are blocked with memory encapsulated somewhere 
> into an object or a package.
> 
> > 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.
> 
> That is called "monitor". It can be used to implement the semaphore too, 
> but nobody does that. In most cases monitor is better than semaphore 
> when that comes in question.
> 
> Semaphore has little if no use when k>1. Only mutex (semaphore k=1) is 
> actively used.
> 
> > Is there a better approach?
> 
> Sometimes monitor is better sometimes mutex is.
> 
> Regarding mutex what kind of are you looking for? Plain? Reentrant? 
> Read-write mutex? Arrays of mutexes?
> 
> In Ada synchronization objects like mutex are implemented using 
> protected object. A plain mutex or semaphore is trivial to implement.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Hello Dmitry,

Yes, resources is a better term.  What I'm looking for -- well, still learning about it, I'm quite new to this -- is really to learn more about mutexes.  I think I got my terminologies mixed up.  What I really meant is a mutex, 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 your help, but for now I'd like to figure things out on my own, if I hit a wall I will post here.


  reply	other threads:[~2016-08-27 18:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25  0:41 How to simulate semaphores with Ada's tasks? Andrew Shvets
2016-08-25  1:04 ` Jeffrey R. Carter
2016-08-25  1:44   ` Andrew Shvets
2016-08-27 21:36   ` Andrew Shvets
2016-08-28  1:04     ` Jeffrey R. Carter
2016-08-28  1:59       ` Andrew Shvets
2016-08-25  7:39 ` Dmitry A. Kazakov
2016-08-27 18:06   ` Andrew Shvets [this message]
2016-08-25  7:55 ` G.B.
replies disabled

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