Emscripten has pthread support (as well as C++ threads), but we don't currently implement them. This fixes that by adding the necessary code. The one thing I'm not sure about is setting the pool size. The docs suggest that you really want to do this to ensure that your code works correctly, but the number should really be configurable, not sure how to set that. Fixes #6684pull/6688/head
parent
b2f86c461b
commit
771b0d3ffb
8 changed files with 98 additions and 16 deletions
@ -0,0 +1,6 @@ |
||||
## Emscripten (emcc) now supports threads |
||||
|
||||
In addition to properly setting the compile and linker arguments, a new meson |
||||
builtin has been added to control the PTHREAD_POOL_SIZE option, |
||||
`-D<lang>_thread_count`, which may be set to any integer value greater than 0. |
||||
If it set to 0 then the PTHREAD_POOL_SIZE option will not be passed. |
@ -0,0 +1,10 @@ |
||||
project( |
||||
'threads', |
||||
'c', 'cpp', |
||||
default_options : ['cpp_std=c++11'], |
||||
) |
||||
|
||||
dep_threads = dependency('threads') |
||||
|
||||
executable('threads-c', 'threads.c', dependencies : dep_threads) |
||||
executable('threads-c++', 'threads.cpp', dependencies : dep_threads) |
@ -0,0 +1,21 @@ |
||||
#include <stdio.h> |
||||
#include <unistd.h> |
||||
#include <pthread.h> |
||||
|
||||
void inthread(void * args) { |
||||
sleep(1); |
||||
printf("In thread\n"); |
||||
} |
||||
|
||||
int main() { |
||||
#ifdef __EMSCRIPTEN_PTHREADS__ |
||||
pthread_t thread_id; |
||||
printf("Before Thread\n");
|
||||
pthread_create(&thread_id, NULL, (void *)*inthread, NULL);
|
||||
pthread_join(thread_id, NULL);
|
||||
printf("After Thread\n"); |
||||
return 0; |
||||
#else |
||||
# error "threads not enabled\n" |
||||
#endif |
||||
} |
@ -0,0 +1,13 @@ |
||||
#include <unistd.h> |
||||
#include <iostream> |
||||
#include <thread> |
||||
|
||||
int main(void) { |
||||
std::cout << "Before thread" << std::endl; |
||||
std::thread t([]() { |
||||
sleep(1); |
||||
std::cout << "In a thread." << std::endl; |
||||
}); |
||||
t.join(); |
||||
std::cout << "After thread" << std::endl; |
||||
} |
Loading…
Reference in new issue