Created
February 28, 2013 07:11
-
-
Save sonygod/5054867 to your computer and use it in GitHub Desktop.
动态创建多线程
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ; | |
import neko.vm.Thread; | |
/** | |
* ... | |
* @author sonygod | |
*/ | |
class TestDTread | |
{ | |
private var num:Int = 0; | |
public function new() | |
{ | |
var len =4; | |
var sum = 0; | |
for (ii in 0...len) { | |
var thread1 = Thread.create(thread1Call); | |
var thread2 = Thread.create(thread2Call); | |
thread1.sendMessage(Thread.current()); | |
thread1.sendMessage(thread2); | |
thread2.sendMessage(Thread.current()); | |
} | |
for (ii in 0...len) { | |
Thread.readMessage(true); | |
} | |
trace("finish"); | |
} | |
function thread1Call():Void { | |
var main :Thread= Thread.readMessage(true); | |
var thread2 :Thread= Thread.readMessage(true); | |
trace("thread1 got it "); | |
for (ii in 0...100) { | |
thread2.sendMessage("sum" + ii); | |
Sys.sleep(1 ); | |
} | |
main.sendMessage("done"); | |
} | |
function thread2Call():Void { | |
var main :Thread = Thread.readMessage(true); | |
trace("thread2 got it "); | |
for (ii in 0...100) { | |
trace("thread2--"+Thread.readMessage(true)); | |
} | |
main.sendMessage("done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment