Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tid.isDone() not working #131

Closed
leepc12 opened this issue May 23, 2016 · 5 comments
Closed

tid.isDone() not working #131

leepc12 opened this issue May 23, 2016 · 5 comments

Comments

@leepc12
Copy link

leepc12 commented May 23, 2016

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
Copy link
Owner

pcingola commented Jun 7, 2016

Fixed in latest version (Build '2016-06-06').

@pcingola pcingola closed this as completed Jun 7, 2016
@leepc12
Copy link
Author

leepc12 commented Aug 13, 2016

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.

@leepc12
Copy link
Author

leepc12 commented Aug 23, 2016

I created a PR to fix this.

@DoaneAS
Copy link

DoaneAS commented Feb 11, 2017

Is BDS being actively maintained?

@pcingola
Copy link
Owner

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants