This repository was archived by the owner on Aug 9, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMain.hx
More file actions
55 lines (42 loc) · 1.18 KB
/
Main.hx
File metadata and controls
55 lines (42 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package;
// http://old.haxe.org/doc/neko/threads
// http://api.haxe.org/cpp/vm/Thread.html
// http://www.joshuagranick.com/2012/08/24/using-threads-with-nme/
// http://api.haxe.org/cpp/vm/Deque.html
#if cpp
import cpp.vm.Deque;
import cpp.vm.Thread;
#elseif neko
import neko.vm.Deque;
import neko.vm.Thread;
#end
class Main {
private static function sendData ():Void {
var data:Deque<Int> = Thread.readMessage (true);
for (i in 0...10) {
data.push (i);
trace ("Sending data: " + i);
Sys.sleep (0.1);
}
}
private static function receiveData ():Void {
var data:Deque<Int> = Thread.readMessage (true);
for (i in 0...10) {
trace ("Receiving data: " + data.pop (true));
}
}
public static function main () {
//----------------------------------------------------------------------
trace('--- Exchange data between threads ---');
var data = new Deque <Int> ();
var first = Thread.create (sendData);
var second = Thread.create (receiveData);
first.sendMessage (data);
second.sendMessage (data);
trace ("This message will not wait for the result");
for (i in 0...10) {
trace ("Main Thread: " + i);
Sys.sleep (0.5);
}
}
}