Open TheModMaker opened 4 years ago
There is another data race between the two for the CURL data. The NetworkThread
reads the individual requests as part of curl_multi_perform
, but XMLHttpRequest
reads the request directly on other threads.
This should be easily detectable with Valgrind: valgrind --tool=helgrind out/Debug/demo
.
Currently,
XMLHttpRequest
doesn't handle locks and threads correctly. It is mainly used on the JS main thread, so we don't need locks for that; but it also is called from theNetworkThread
for network events. This multi-thread usage requires locks. Currently, the background calls also modify fields that are directly exposed to JavaScript, and the mapping framework doesn't handle locks, so these can result in a data race.Also, since
XMLHttpRequest
andNetworkThread
call into each other, it might be possible to deadlock, if not handled correctly. This should be refactored to avoid this bidirectional calls and deadlock possibility.The only time we need to interact with the background threads is to (a) fire JS events, or (b) send or receive data. The data handling could be done by
NetworkThread
instead. The event firing could be done by havingNetworkThread
schedule the callbacks to happen on the JS main thread instead. This allowsXMLHttpRequest
to only work on the JS main thread and avoids complex multi-thread work.