Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Maping of Ada tasks on the plateforme OS threads model

6 views
Skip to first unread message

Hibou57 (Yannick Duchêne)

unread,
Jun 27, 2009, 8:35:14 PM6/27/09
to
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.

sjw

unread,
Jun 28, 2009, 12:31:35 PM6/28/09
to
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.

Hibou57 (Yannick Duchêne)

unread,
Jun 29, 2009, 4:56:13 PM6/29/09
to
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.

Georg Bauhaus

unread,
Jun 29, 2009, 6:45:38 PM6/29/09
to
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;

0 new messages