Skip to content

USE_PTHREADS freezes Firefox Nightly 42.0a1 #3636

Closed
@Kagami

Description

@Kagami

Hi. I'm trying to make simple threads example to work with Emscripten's -s USE_PTHREADS=1 option but unfortunately it doesn't work with latest stable Emscripten and Firefox Nightly. Probably I'm doing something stupidly wrong, sorry for that.

Here is simple pthread example:

$ cat 1.c 
#include <stdio.h>
#include <pthread.h>

void *thread_fn(void *arg) {
    printf("Thread done\n");
    return NULL;
}

int main(void)
{
    pthread_t thread1, thread2;
    pthread_create(&thread1, NULL, thread_fn, NULL);
    pthread_create(&thread2, NULL, thread_fn, NULL);
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);
    printf("Done\n");
    return 0;
}

I'm compiling it with the following options to index.html:

$ emcc -s USE_PTHREADS=1 1.c -o index.html
warning: unresolved symbol: posix_spawn
warning: unresolved symbol: posix_spawn_file_actions_adddup2
warning: unresolved symbol: posix_spawn_file_actions_init
warning: unresolved symbol: posix_spawn_file_actions_destroy

When I open the resulting page in Firefox, it freezes the window. If I stop the script, I got the following text at page's console:

Preallocating 1 workers for a pthread spawn pool.
Preallocating 1 workers for a pthread spawn pool.
Thread done
Thread done

and this in the browser's console:

pre-main prep time: 6 ms t:1245:13

Preallocating 1 workers for a pthread spawn pool. t:1233:13
Error: Script terminated by timeout at:
_emscripten_futex_wait@http://127.0.0.1:4444/t/index.js:5479:17
_pthread_join@http://127.0.0.1:4444/t/index.js:6862:9
_main@http://127.0.0.1:4444/t/index.js:8698:3
asm._main@http://127.0.0.1:4444/t/index.js:34880:8
callMain@http://127.0.0.1:4444/t/index.js:35041:15
doRun@http://127.0.0.1:4444/t/index.js:35100:42
run/<@http://127.0.0.1:4444/t/index.js:35111:7
 index.js:5479:17
Thread done

If I compile the code with pool size option:

emcc -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=2 1.c -o index.html

I got the following error at the page instead:

Preallocating 2 workers for a pthread spawn pool.
Assertion failed: you need to wait for the runtime to be ready (e.g. wait for main() to be called)

I tried to compile test_pthread_join.cpp from the Emscripten's test suite but got the same result.

emcc -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=-1 -s PTHREAD_HINT_NUM_CORES=-1 1.c -o index.html

gives me Thread setup popup on page load but after that I got errors in console and can't see the threads output:

ReferenceError: _emscripten_force_num_logical_cores is not defined index.js:1631:5
still waiting on run dependencies: t:1245:13
dependency: pthreads_querycores t:1245:13
(end of list) t:1245:13
still waiting on run dependencies: t:1245:13
dependency: pthreads_querycores t:1245:13
(end of list) t:1245:13
still waiting on run dependencies: t:1245:13
dependency: pthreads_querycores t:1245:13
(end of list) t:1245:13

Am I doing something wrong? I'm using emscripten/tag-1.34.3 and Firefox 42.0a1 (2015-07-22).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions