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