comp.lang.ada
 help / color / mirror / Atom feed
From: James Rogers <jimmaureenrogers@att.net>
Subject: Re: C omega
Date: Sun, 06 Jun 2004 02:21:20 GMT
Date: 2004-06-06T02:21:20+00:00	[thread overview]
Message-ID: <Xns94FFCEA71DB7jimmaureenrogers@204.127.36.1> (raw)
In-Reply-To: 2if4rkFm3j4bU1@uni-berlin.de

Roland Illig <roland.illig@gmx.de> wrote in news:2if4rkFm3j4bU1@uni-
berlin.de:

> Adrian Knoth wrote:
>> I wouldn't say it's the same code. Unfortunately you haven't mentioned
>> the website where you found this example. Otherwise it would be
>> possible to see what is really ment instead of wild guessing.
> 
> http://www.google.de/search?q=public+void+Shared+async+idle+&ie=UTF-8
> 
> http://research.microsoft.com/~nick/polyphony/intro.htm

It would appear from these links that the concurrency in C omega is taken
directly from polyphonic C# (or perhaps C omega is a new name for
polyphonic C#).

The original example:

class ReaderWriter {

   ReaderWriter() {
      Idle();
   }

   void Exclusive() & private async Idle() {
   }

   void ReleaseExclusive() {
      Idle(); 
   } 

   void Shared() & private async Idle() {
      S(1);
   }

   void Shared() & private async S(int n) {
      S(n+1);
   }

   void ReleaseShared() & private async S(int n) { 
      if (n == 1) Idle(); else S(n-1); 
   }
}

is clearly an example of a read/write lock. The public methods
Exclusive(), ReleaseExclusive(), Shared(), and ReleaseShared()
are synchronous methods. They will not complete until a matching
private asynchronous method (in this case Idle() or S()) completes.

This code produces a behavior similar to the following Ada code:

protected lock is
   entry Exclusive;
   procedure Release_Exclusive;
   entry Shared;
   entry Release_Shared;
private
   N : Natural := 0;
   Idle : Boolean := True;
end lock;

protected body lock is
  entry Exclusive when Idle is
  begin
      Idle := False;
  return;
  procedure Release_Exclusive is
  begin
      Idle := True;
  end Release_Exclusive;
  entry Shared when Idle or N > 0 is
  begin
      Idle := False;
      N := N + 1;
  end Shared;
  entry Release_Shared when N > 1 is
  begin
     N := N - 1;
     if N = 0 then
        Idle := True;
     end if;
  end Release_Shared;
end lock;

Note that my Ada explicitly sets Idle to false
whereas the C# (or C omega) code simply fails to 
call Idle(). The weakness in algorithm is that
a writer can simply call Release_Exclusive 
immediately before calling Exclusive. This will
cause a collision between shared and exclusive
access.

In other words, the example contains a fatal flaw.

Jim Rogers



  reply	other threads:[~2004-06-06  2:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-05 14:25 C omega Pascal Obry
2004-06-05 17:49 ` Wes Groleau
2004-06-05 22:06 ` Adrian Knoth
2004-06-05 23:55   ` Roland Illig
2004-06-06  2:21     ` James Rogers [this message]
2004-06-06  2:53       ` Wes Groleau
2004-06-06 18:09         ` [off-topic] bad puns Wes Groleau
2004-06-06  9:47       ` C omega Pascal Obry
2004-06-06 12:32         ` James Rogers
2004-06-06  9:49   ` Pascal Obry
2004-06-06 22:14   ` Georg Bauhaus
2004-06-07 11:17     ` I R T
2004-06-07 15:45     ` Adrian Knoth
replies disabled

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