tid.isDone() not working
leepc12 opened this issue · 5 comments
leepc12 commented
For tasks executed in par
function, tid.isDone() does not work. You can run the following example to replicate this error.
#!/usr/bin/env bds
string[] tids_all
sleep_sec := 2 help sleep_sec
num_rep := 16 help num_rep
nth_spp := 3 help nth_spp
nth := 10 help nth
par spp()
wait
for ( string tid : tids_all ) {
print("\t$tid : "+tid.isDone()+", "+tid.isDoneOk()+", "+tid.exitCode()+"\n")
}
void spp() {
for (int i=1; i<=num_rep; i++) spp_sub(i)
}
void spp_sub(int i) {
time := min(i,sleep_sec)
taskName := "spp $i"
tid := task {
sys echo $(date)": spp $i started."
sys sleep $time
sys echo $(date)": spp $i done."
}
register_par( tid, nth_spp )
}
void register_par( string tid, int nth_task ) {
if ( tid == "" ) return
tids_all.add(tid)
}
pcingola commented
Fixed in latest version (Build '2016-06-06').
leepc12 commented
Please reopen this issue. This bug still persists.
tid.isDone() does not work if tid.isDone() is called in a different thread.
#!/usr/bin/env bds
string tid1
par test1()
par test2()
void test1() {
tid1 = task {
sys echo "test1... 10 seconds left"
sys sleep 5
sys echo "test1... 5 seconds left"
sys sleep 5
sys echo "test1 is done."
}
while( !tid1.isDone() ) {
print("\ttest1(): Waiting until tid1 is done... $tid1\n")
sleep(1)
}
}
void test2() {
while( !tid1.isDone() ) {
print("\ttest2(): Waiting until tid1 is done... $tid1\n")
sleep(1)
}
}
Result: test1() catches that tid1 is done but test2() cannot.
test2(): Waiting until tid1 is done...
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1... 10 seconds left
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1... 5 seconds left
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1 is done.
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test1(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
test2(): Waiting until tid1 is done... b.bds.20160813_034657_800_parallel_22/task.b.line_12.id_1
Fixing this bug is very important for me to implement limiting maximum # of threads for my bio pipeline. It has a while loop to check if tasks in other threads are done.
DoaneAS commented
Is BDS being actively maintained?
pcingola commented
Yes