1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- G N A T . T H R E A D S --
10 -- Copyright (C) 1998-2000 Ada Core Technologies, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 ------------------------------------------------------------------------------
34 -- This package provides facilities for creation of foreign threads for
35 -- use as Ada tasks. In order to execute general Ada code, the run-time
36 -- system must know about all tasks. This package allows foreign code,
37 -- e.g. a C program, to create a thread that the Ada run-time knows about.
41 package GNAT
.Threads
is
43 type Void_Ptr
is access all Integer;
45 function Create_Thread
46 (Code
: System
.Address
; -- pointer
47 Parm
: Void_Ptr
; -- pointer
48 Size
: Natural; -- int
49 Prio
: Integer) -- int
50 return System
.Address
;
51 pragma Export
(C
, Create_Thread
, "__gnat_create_thread");
52 -- Creates a thread with the given (Size) stack size in bytes, and
53 -- the given (Prio) priority. The task will execute a call to the
54 -- procedure whose address is given by Code. This procedure has
57 -- void thread_code (void *id, void *parm);
59 -- where id is the id of the created task, and parm is the parameter
60 -- passed to Create_Thread. The called procedure is the body of the
61 -- code for the task, the task will be automatically terminated when
62 -- the procedure returns.
64 -- This function returns the Ada Id of the created task that can then be
65 -- used as a parameter to the procedures below.
69 -- extern void *__gnat_create_thread
70 -- (void (*code)(void *, void *), void *parm, int size, int prio);
72 procedure Destroy_Thread
(Id
: System
.Address
);
73 pragma Export
(C
, Destroy_Thread
, "__gnat_destroy_thread");
74 -- This procedure may be used to prematurely abort the created thread.
75 -- The value Id is the value that was passed to the thread code procedure
76 -- at activation time.
80 -- extern void __gnat_destroy_thread (void *id);
82 procedure Get_Thread
(Id
: System
.Address
; Thread
: System
.Address
);
83 pragma Export
(C
, Get_Thread
, "__gnat_get_thread");
84 -- This procedure is used to retrieve the thread id of a given task.
85 -- The value Id is the value that was passed to the thread code procedure
86 -- at activation time.
87 -- Thread is a pointer to a thread id that will be updated by this
92 -- extern void __gnat_get_thread (void *id, pthread_t *thread);