Created
January 17, 2022 13:02
-
-
Save yakkomajuri/7d6786baf84ff9735a68cb3720136fa5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function atomicsWaitLoop (port : MessagePort, sharedBuffer : Int32Array) { | |
if (!useAtomics) return; | |
// This function is entered either after receiving the startup message, or | |
// when we are done with a task. In those situations, the *only* thing we | |
// expect to happen next is a 'message' on `port`. | |
// That call would come with the overhead of a C++ → JS boundary crossing, | |
// including async tracking. So, instead, if there is no task currently | |
// running, we wait for a signal from the parent thread using Atomics.wait(), | |
// and read the message from the port instead of generating an event, | |
// in order to avoid that overhead. | |
// The one catch is that this stops asynchronous operations that are still | |
// running from proceeding. Generally, tasks should not spawn asynchronous | |
// operations without waiting for them to finish, though. | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment