46
47
Returns the current thread.
48
49
public static function current() {
49
return new Thread(thread_current());
50
return new Thread(untyped __global__.__hxcpp_thread_current());
53
54
Creates a new thread that will execute the [callb] function, then exit.
55
56
public static function create( callb : Void -> Void ) {
56
return new Thread(thread_create(function(_) { callb(); },[]));
57
return new Thread(untyped __global__.__hxcpp_thread_create(callb));
62
63
returns [null] if no message is available.
64
65
public static function readMessage( block : Bool ) : Dynamic {
65
return thread_read_message(block);
66
return untyped __global__.__hxcpp_thread_read_message(block);
68
69
function __compare(t) {
69
70
return untyped handle == t.handle;
73
Starts an OS message loop after [osInitialize] has been done.
74
In that state, the UI handled by this thread will be updated and
75
[sync] calls can be performed. The loop returns when [exitLoop] is
76
called for this thread.
78
public static function osLoop() {
79
if( os_loop == null ) throw "Please call osInitialize() first";
84
The function [f] will be called by this thread if it's in [osLoop].
85
[sync] returns immediatly. See [osInitialize] remarks.
87
public function sync( f : Void -> Void ) {
92
The function [f] will be called by this thread and the calling thread
93
will wait until the result is available then return its value.
95
public function syncResult<T>( f : Void -> T ) : T {
96
if( this == current() )
98
var v = new cpp.vm.Lock();
111
public function exitLoop() {
112
os_loop_stop(handle);
116
If you want to use the [osLoop], [sync] and [syncResult] methods, you
117
need to call [osInitialize] before creating any thread or calling [current].
118
This will load [os.ndll] library and initialize UI methods for each thread.
120
public static function osInitialize() {
121
os_loop = cpp.Lib.load("os","os_loop",0);
122
os_loop_stop = cpp.Lib.load("os","os_loop_stop",1);
123
os_sync = cpp.Lib.load("os","os_sync",2);
126
static var os_loop = null;
127
static var os_loop_stop = null;
128
static var os_sync = null;
131
static var thread_create = cpp.Lib.load("std","thread_create",2);
132
static var thread_current = cpp.Lib.load("std","thread_current",0);
133
static var thread_send = cpp.Lib.load("std","thread_send",2);
134
static var thread_read_message = cpp.Lib.load("std","thread_read_message",1);
75
You_need_to_define_HXCPP_MULTI_THREADED_to_use_the_Thread_class