1 -- Created on: 2006-03-10
2 -- Created by: data exchange team
3 -- Copyright (c) 2006-2014 OPEN CASCADE SAS
5 -- This file is part of Open CASCADE Technology software library.
7 -- This library is free software; you can redistribute it and/or modify it under
8 -- the terms of the GNU Lesser General Public License version 2.1 as published
9 -- by the Free Software Foundation, with special exception defined in the file
10 -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 -- distribution for complete text of the license and disclaimer of any warranty.
13 -- Alternatively, this file may be used under the terms of Open CASCADE
14 -- commercial license or contractual agreement.
18 ---Purpose: A simple platform-intependent interface to execute
19 -- and control threads.
22 Address from Standard,
23 ThreadId from Standard,
25 ThreadFunction from OSD
27 Create returns Thread;
28 ---Purpose: Empty constructor
30 Create (func: ThreadFunction) returns Thread;
31 ---Purpose: Initialize the tool by the thread function
33 -- Note: On Windows, you might have to take an address of the thread
34 -- function explicitly to pass it to this constructor without compiler error
36 Create (other: Thread) returns Thread;
37 ---Purpose: Copy constructor
39 Assign (me: in out; other: Thread);
40 ---Purpose: Copy thread handle from other OSD_Thread object.
41 ---C++: alias operator =
44 ---Purpose: Destructor. On Windows, closes handle to the thread.
45 -- On UNIX/Linux, does nothing.
48 SetPriority (me: in out; thePriority: Integer from Standard);
49 ---Putpose: Assign the thread to the given priotity, taking it
50 -- : as relative value. The absolute priotity of theThread will
51 -- : be the one of the caller of this function PLUS
52 -- : 'thePriority' parameter
53 -- Note: Currently implemented on Windows only.
55 SetFunction (me: in out; func: ThreadFunction);
56 ---Purpose: Initialize the tool by the thread function.
57 -- If the current thread handle is not null, nullifies it.
59 -- Note: On Windows, you might have to take an address of the thread
60 -- function explicitly to pass it to this method without compiler error
62 Run (me: in out; data: Address = 0; WNTStackSize: Integer = 0) returns Boolean;
63 ---Purpose: Starts a thread with thread function given in constructor,
64 -- passing the specified input data (as void *) to it.
65 -- The parameter \a WNTStackSize (on Windows only)
66 -- specifies size of the stack to be allocated for the thread
67 -- (by default - the same as for the current executable).
68 -- Returns True if thread started successfully
71 ---Purpose: Detaches the execution thread from this Thread object,
72 -- so that it cannot be waited.
73 -- Note that mechanics of this operation is different on
74 -- UNIX/Linux (the thread is put to detached state) and Windows
75 -- (the handle is closed).
76 -- However, the purpose is the same: to instruct the system to
77 -- release all thread data upon its completion.
79 Wait (me) returns Boolean;
80 Wait (me; result: out Address) returns Boolean;
81 ---Purpose: Wait till the thread finishes execution.
82 -- Returns True if wait was successful, False in case of error.
84 -- If successful and \a result argument is provided, saves the pointer
85 -- (void*) returned by the thread function in \a result.
87 -- Note however that it is advisable not to rely upon returned result
88 -- value, as it is not always the value actually returned by the thread
89 -- function. In addition, on Windows it is converted via DWORD.
90 Wait (me; time: Integer; result: out Address) returns Boolean;
91 ---Purpose: Waits for some time and if the thread is finished,
92 -- it returns the result.
93 -- The function returns false if the thread is not finished yet.
95 GetId (me) returns ThreadId;
96 ---Purpose: Returns ID of the currently controlled thread ID,
97 -- or 0 if no thread is run
99 Current (myclass) returns ThreadId;
100 ---Purpose: Auxiliary: returns ID of the current thread
103 myFunc: ThreadFunction from OSD; -- A function to execute
104 myThread: PThread from OSD; -- Thread handle
105 myThreadId: ThreadId from Standard; -- Thread identifier
106 myPriority: Integer from Standard; -- Thread priority