comp.lang.ada
 help / color / mirror / Atom feed
* Maping of Ada tasks on the plateforme OS threads model
@ 2009-06-28  0:35 Hibou57 (Yannick Duchêne)
  2009-06-28 16:31 ` sjw
  0 siblings, 1 reply; 4+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-06-28  0:35 UTC (permalink / raw)


Hello every body out there,

As I will have to port a C application (previously started with C, to
have a kind of quick mock up and make direct use of some OS API
functions) which importantly relies on threads.

As things are 1) going fine with this thread model and as 2) the
application gonna be more complex than it is actually, I was thinking
about 1) keep the same low level thread model 2) while using Ada for
further developpement to have a cleaner and more readable design.

Happily, it seems most of Ada compiler designers are wise enought to
try to map Ada task to the underlying OS thread model.

I've found two starting points about it :

http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gnat_rm/Mapping-Ada-Tasks-onto-the-Underlying-Kernel-Threads.html
and
http://www.rrsoftware.com/html/prodinf/triadapaper/triada.mainsrc.html

The RRSoftware page makes reference to Win32s which is not use any
more, so I apologize for this rather old document. I've found another
page about Janus Ada tasking and Windows threads, but after an hour
searching it back, I'm still not able to get it back.

Well, there is no real trouble I want to submit, I think this gonna be
Ok for me. I'm just opening this thread beceause I was thinking this
is an intereresting subject which may be of interest for people
interested in porting some applications from this very widely used and
famous C to Ada, as well as to people aware of efficiency matters (a
big spot with threads).

Peoples having any experiences to share about it are welcome :)

Pleased to read you soon

Y.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Maping of Ada tasks on the plateforme OS threads model
  2009-06-28  0:35 Maping of Ada tasks on the plateforme OS threads model Hibou57 (Yannick Duchêne)
@ 2009-06-28 16:31 ` sjw
  2009-06-29 20:56   ` Hibou57 (Yannick Duchêne)
  0 siblings, 1 reply; 4+ messages in thread
From: sjw @ 2009-06-28 16:31 UTC (permalink / raw)


On Jun 28, 1:35 am, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> wrote:

> As things are 1) going fine with this thread model and as 2) the
> application gonna be more complex than it is actually, I was thinking
> about 1) keep the same low level thread model 2) while using Ada for
> further developpement to have a cleaner and more readable design.

My experience isn't extensive but I've certainly regretted using C++
for an application whose threading got more complex than we had
planned originally.

If you are using GNAT, be aware of GNAT.Threads; on some operating
systems (VxWorks, for instance) you must call
GNAT.Threads.Register_Thread in Ada code called (via C, for example)
from an OS thread before you do anything involving the RTS (string
catenation, ...). Other compilers will have their own way of dealing
with this.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Maping of Ada tasks on the plateforme OS threads model
  2009-06-28 16:31 ` sjw
@ 2009-06-29 20:56   ` Hibou57 (Yannick Duchêne)
  2009-06-29 22:45     ` coroutines (Maping of Ada tasks on the plateforme OS threads model) Georg Bauhaus
  0 siblings, 1 reply; 4+ messages in thread
From: Hibou57 (Yannick Duchêne) @ 2009-06-29 20:56 UTC (permalink / raw)


On 28 juin, 18:31, sjw <simon.j.wri...@mac.com> wrote:
> If you are using GNAT, be aware of GNAT.Threads; on some operating
> systems (VxWorks, for instance) you must call
> GNAT.Threads.Register_Thread in Ada code called (via C, for example)
> from an OS thread before you do anything involving the RTS (string
> catenation, ...). Other compilers will have their own way of dealing
> with this.

I've never heard about VxWorks before. It is a real time OS, as said
Yahoo search.

A note on Windows which tells to be careful when using GetLastError:

> It is not possible to use GetLastError and SetLastError when tasking,
> protected records, or exceptions are used. In these cases, in order to
> implement Ada semantics, the GNAT run-time system calls certain Win32 routines
> that set the last error variable to 0 upon success. It should be possible to
> use GetLastError and SetLastError when tasking, protected record, and
> exception features are not used, but it is not guaranteed to work.

http://www.adacore.com/wp-content/files/auto_update/gnat-unw-docs/html/gnat_ugn_36.html

By the ways, I'm looking for the best way to do coroutines with Ada,
without tasking (none-recursive coroutines, so no separate stack is
needed, just global storage for local variables). Yes, this can be
achieved with a select/when statement and a state enumeration, but
this way is not very clean nor nice.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: coroutines (Maping of Ada tasks on the plateforme OS threads model)
  2009-06-29 20:56   ` Hibou57 (Yannick Duchêne)
@ 2009-06-29 22:45     ` Georg Bauhaus
  0 siblings, 0 replies; 4+ messages in thread
From: Georg Bauhaus @ 2009-06-29 22:45 UTC (permalink / raw)


Hibou57 (Yannick Duch�ne) wrote:

> By the ways, I'm looking for the best way to do coroutines with Ada,
> without tasking (none-recursive coroutines, so no separate stack is
> needed, just global storage for local variables). Yes, this can be
> achieved with a select/when statement and a state enumeration, but
> this way is not very clean nor nice.

Not necessarily the best, or even a good way, the
following is an outline. (Yes, there is recursion BTW,
but it isn't crucial.)

procedure News32 is

   Max_Statements: constant := 10;
   type Statement_Index is range 1 .. Max_Statements;

   A_Index,
   B_Index : Statement_Index;

   procedure A;
   procedure B;

   Waiting: Boolean;
   Result: Integer;

   procedure A is
   begin
      case A_Index is
         when 1 => goto STMT1;
         when 2 => goto STMT2;
         when others => raise Program_Error;
      end case;

      <<STMT1>>
      if Waiting then
         B;
         return;
      end if;
      Result := 1;

      <<STMT2>>
      Result := 2;

   end A;

   procedure B is
   begin
      case B_Index is
         when 1 => goto STMT1;
         when others => raise Program_Error;
      end case;

      <<STMT1>>
      A_Index := A_Index + 1;
      A;  -- resumes A at A.STMT2
   end B;

begin
   Result := 0;
   Waiting := True;
   A_Index := 1;
   B_Index := 1;
   A;
   pragma Assert(Result = 2);
end News32;



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-06-29 22:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-28  0:35 Maping of Ada tasks on the plateforme OS threads model Hibou57 (Yannick Duchêne)
2009-06-28 16:31 ` sjw
2009-06-29 20:56   ` Hibou57 (Yannick Duchêne)
2009-06-29 22:45     ` coroutines (Maping of Ada tasks on the plateforme OS threads model) Georg Bauhaus

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