Dear Experts,

I have code where I (1) use MAIN_THREAD_ASYNC_EM_ASM to 
queue code to run on the main thread from a background 
thread, and (2) protect some data structures from concurrent 
access using pthread mutexes. I am compiling with -pthread.

I know that locking a mutex on the main thread involves 
polling. My question is: can work that has been submitted by 
MAIN_THREAD_ASYNC_EM_ASM run when this polling occurs?

It looks to me as if it does, which is surprising! But this is 
hard to debug and I may have misinterpreted what is going 
on.


I.e. (pseudo-code):

// Global:

int i;  // Only access this on the main thread!
std::string s;  // Only access this with mut locked!
std::mutex mut;

// Main thread, e.g. in WebGL drawing code, or an 
// input event handler, etc:

i = 0;
mut.lock();
assert(i == 0);  // Can this fail?
foo(s);
mut.unlock();

// Background (worker) thread:

void modify_i() { i++; }

MAIN_THREAD_ASYNC_EM_ASM({
  Module.ccall('modify_i', null);
});


Thanks,

Phil.


-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/1755783746635%40dmwebmail.dmwebmail.chezphil.org.

Reply via email to