Fix/Simplify the atomic.wait/nofity implementations#2044
Fix/Simplify the atomic.wait/nofity implementations#2044wenyongh merged 3 commits intobytecodealliance:mainfrom
Conversation
|
Thank you @wenyongh ! Is this PR about the hanging problem? Also I opened an issue about it in wasi-libc with my investigation, but since you made PRs I suppose you discovered the same things |
The root cause of the hang is that the opcodes generated of a_store is not atomic for interpreter mode, as you mentioned, I submitted a PR to fix it in wasi-libc.
The data races seems to be normal behavior, the int old;
do old = *p;
while (a_cas(p, old, v) != old);
return old;Here old = *p is not atomic, and a_cas(p, old, v) is atomic, if two threads operate on the same address p, data races may be reported by sanitizer. |
Gotcha, make sense. I will ran tests with TSAN and multiple times as I did to find hanging situations
Hm, isn't it needed to be fixed then? What's the benefit to keep it that way? |
|
Multiple runs and running under TSAN passed 👍 |
…#2044) Use the shared memory's shared_mem_lock to lock the whole atomic.wait and atomic.notify processes, and use it for os_cond_reltimedwait and os_cond_notify, so as to make the whole processes actual atomic operations: the original implementation accesses the wait address with shared_mem_lock and uses wait_node->wait_lock for os_cond_reltimedwait, which is not an atomic operation. And remove the unnecessary wait_map_lock and wait_lock, since the whole processes are already locked by shared_mem_lock.
Use the shared memory's shared_mem_lock to lock the whole atomic.wait and
atomic.notify processes, and use it for os_cond_reltimedwait and os_cond_notify,
so as to make the whole processes actual atomic operations:
the original implementation accesses the wait address with shared_mem_lock
and uses wait_node->wait_lock for os_cond_reltimedwait, which is not atomic
operation.
And remove the unnecessary wait_map_lock and wait_lock, since the whole
processes are already locked by shared_mem_lock.