comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to simulate semaphores with Ada's tasks?
Date: Thu, 25 Aug 2016 09:39:01 +0200
Date: 2016-08-25T09:39:01+02:00	[thread overview]
Message-ID: <npm7c0$fme$1@gioia.aioe.org> (raw)
In-Reply-To: 35ae841e-5947-44e9-a8d4-479cf40c4277@googlegroups.com

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


  parent reply	other threads:[~2016-08-25  7:39 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 [this message]
2016-08-27 18:06   ` Andrew Shvets
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