comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com (Tom Moran)
Subject: Re: Blocking protected ops (was: Tasks and C/C++ code)
Date: 1998/11/27
Date: 1998-11-27T00:00:00+00:00	[thread overview]
Message-ID: <365f243d.10100378@news.pacbell.net> (raw)
In-Reply-To: 73mo00$24ik$1@news.gate.net

The Claw Windows binding uses WSAAsyncGetHostByName, which gets
around most of the blocking.  But more generally, to call a blocking
routine in a task safe way, Mats Weber's example is basically what
you need to do.

If you are going to have multiple semaphores, you will want to
create a protected semaphore type, so you can declare different
semaphores for different resources.

If your code between Seize and Release is complex, you might find it
less error-prone to create a controlled type whose Initialize calls
Seize and whose Finalize calls Release, to make sure those are both
called properly, ie something like this:

protected type Semaphore -- like Mats Weber's example, but a type

type Access_Semaphore is access all Semaphore;

type Seizer(What : Access_Semaphore)
  is new Ada.Finalization.Limited_Controlled with null record;

procedure Initialize(S : in out Siezer);
procedure Finalize(S : in out Siezer);

...

procedure Initialize(S : in out Siezer) is
begin
  Seizer.What.Seize;
end Initialize;

procedure Finalize(S : in out Siezer) is
begin
  Seizer.What.Release;
end Finalize;

...
Gethostbyname_Protector : Semaphore;

function Protected_Gethostbyname (Name : ...
   Owner : Seizer(Gethostbyname_Protector'access);
begin
   return Gethostbyname(Name);
end Protected_Gethostbyname;


Another_Resource : Semaphore;

procedure Something ...
   Owner : Seizer(Another_Resource'access);
begin
   ....
end Something;

etc.
(I've indicated elsewhere some of the reasons I think using
System.Address is a poor idea, but that's an orthogonal issue.)





  reply	other threads:[~1998-11-27  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-09  0:00 Tasks and C/C++ code Barry L. Dorough
1998-11-09  0:00 ` Mats Weber
1998-11-10  0:00 ` dennison
1998-11-11  0:00   ` dbotton
1998-11-11  0:00     ` Barry L. Dorough
1998-11-11  0:00       ` dennison
1998-11-12  0:00       ` Jerry van Dijk
1998-11-13  0:00       ` Mats Weber
1998-11-11  0:00     ` dennison
1998-11-18  0:00     ` Samuel Tardieu
1998-11-19  0:00       ` Mats Weber
1998-11-20  0:00         ` Samuel Tardieu
1998-11-23  0:00           ` Mats Weber
1998-11-23  0:00             ` Tom Moran
1998-11-24  0:00               ` Blocking protected ops (was: Tasks and C/C++ code) Mats Weber
1998-11-24  0:00                 ` Robert I. Eachus
1998-11-25  0:00                   ` Mats Weber
1998-11-25  0:00                     ` Robert I. Eachus
1998-11-26  0:00                       ` Simon Wright
1998-11-27  0:00                         ` David Botton
1998-11-27  0:00                           ` Tom Moran [this message]
1998-11-27  0:00                             ` Jerry van Dijk
1998-11-28  0:00                               ` Tom Moran
1998-11-27  0:00                           ` Mats Weber
1998-11-29  0:00                         ` Tucker Taft
1998-11-30  0:00                           ` Simon Wright
1998-11-25  0:00                     ` Jean-Pierre Rosen
1998-11-27  0:00                       ` Mats Weber
replies disabled

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