-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[WasmFS] Add a hack to work around deadlocks #17869
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
system/lib/wasmfs/thread_utils.h
Outdated
var heartbeat = () => { | ||
_emscripten_proxy_execute_queue($0); | ||
setTimeout(heartbeat, 50); | ||
}; | ||
heartbeat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var heartbeat = () => { | |
_emscripten_proxy_execute_queue($0); | |
setTimeout(heartbeat, 50); | |
}; | |
heartbeat(); | |
var intervalID = setInterval(() => { | |
if (ABORT) { | |
clearInterval(intervalID); | |
} else { | |
_emscripten_proxy_execute_queue($0); | |
} | |
}, 1000); |
When the main thread tries to perform a WasmFS operation that tries to acquire a lock that is already held by another thread that is trying to proxy a backend operation, deadlock can occur. Proxying depends on passing a message to a worker thread and that message has to be relayed through the main thread. When the main thread is spinning on a lock, the proxying message is not relayed and neither thread makes forward progress. Work around the issue by adding a heartbeat event on the dedicated worker thread to make it execute the queue periodically even without receiving a message from the main thread. This allows the proxying thread holding the lock to make forward progress and resolves the deadlock.
92b8fcc
to
23697f3
Compare
system/lib/wasmfs/thread_utils.h
Outdated
}, queue.queue); | ||
|
||
// Sit in the event loop performing work as it comes in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation looks wrong. Should the entire EM_ASM be indented two more?
When the main thread tries to perform a WasmFS operation that tries to acquire a
lock that is already held by another thread that is trying to proxy a backend
operation, deadlock can occur. Proxying depends on passing a message to a worker
thread and that message has to be relayed through the main thread. When the main
thread is spinning on a lock, the proxying message is not relayed and neither
thread makes forward progress.
Work around the issue by adding a heartbeat event on the dedicated worker thread
to make it execute the queue periodically even without receiving a message from
the main thread. This allows the proxying thread holding the lock to make
forward progress and resolves the deadlock.