api: threads, files

This commit is contained in:
hyb1996
2017-12-27 16:47:32 +08:00
parent 25e9c90bf4
commit 729958d419
26 changed files with 652 additions and 339 deletions

View File

@@ -0,0 +1 @@
var i = threads.atomic();

View File

@@ -0,0 +1,11 @@
var running = true;
threads.start(function(){
while(running){
log("running = true");
}
});
sleep(2000);
running = false;
console.info("running = false");

View File

@@ -0,0 +1,26 @@
//启动一个线程
threads.start(function(){
//在线程中每隔1秒打印"线程1"
while(true){
log("线程1");
sleep(1000);
}
});
//启动另一个线程
threads.start(function(){
//在线程中每隔2秒打印"线程1"
while(true){
log("线程2");
sleep(2000);
}
});
//在主线程中每隔3秒打印"主线程"
for(var i = 0; i < 10; i++){
log("主线程");
sleep(3000);
}
//打印100次后退出所有线程
threads.shutDownAll();

View File

@@ -0,0 +1,14 @@
//启动一个无限循环的线程
var thread = threads.start(function(){
while(true){
log("子线程运行中...");
sleep(1000);
}
});
//5秒后关闭线程
sleep(5000);
thread.interrupt();