wasi-libc
wasi-libc copied to clipboard
Fixed malloc with concurrent executions of memory.grow
Other PRs have fixed issues with malloc not being the only code that may use the memory.grow instruction (#377, #394). This merge requests fixes some issues that can occur when running the WebAssembly module multi-threaded and other threads may call memory.grow concurrently while malloc is executed.
Interesting. dlmalloc's documentation for MORECORE_CONTIGUOUS says that it should be correct in the presence of non-continuities, which I assumed would include non-continuities induced by other threads. But seeing code like this:
br = (char*)(CALL_MORECORE(asize));
end = (char*)(CALL_MORECORE(0));
It appears this is not the case. At an initial glance, this PR makes sense to me, though I'm not super familiar with dlmalloc internals.