Firstly, if you are allocating 1.8Gb you are likely pushing up against
browser limits.  Are you specifying a MAXIMUM_MEMORY of larger than 2GB?

Secondly, it looks like you are using wasm workers, which are still
relatively new.  Do you have a version of your code that uses pthreads
instead?  It might tell is if the issue is related to wasm workers.

cheers,
sam

On Thu, May 25, 2023 at 8:06 AM 'Dieter Weidenbrück' via emscripten-discuss
<emscripten-discuss@googlegroups.com> wrote:

> The joy was premature, even with pre-allocated heap size segfaults occur.
> :(
>
> Dieter Weidenbrück schrieb am Donnerstag, 25. Mai 2023 um 16:28:37 UTC+2:
>
>> All,
>> I am experiencing segmentation faults when using wasm workers.
>> Overview:
>> I am working on a project with considerable 3D data sets. The code has
>> been stable for a while when running in the main thread alone. Then I
>> started using js workers (no shared memory), and again all was well.
>> Now I've switched to SharedArrayBuffers and wasm workers, and I keep
>> running into random problems.
>> I have prepared the code such that I can run with 0 workers up to
>> hardware.concurrency workers. All is well with 0 workers, but as soon as I
>> use one or more workers, I keep getting segfaults because of invalid
>> pointers, access out of bounds and similar.
>>
>> What happens in main thread and what in the wasm workers:
>> I allocate all objects in the main thread when importing the 3D file.
>> Then i fire off a function for each object that will do some serious
>> calculations of the data, including allocating and disposing of memory. The
>> workers allocate approx. 300 to 400 MB in addition to the main thread. All
>> this happens in the same sharedArrayBuffer, of course.
>>
>> Here is what I've tried so far:
>> - compiling with SAFE_HEAP=1
>> not a lot of  helpful information,
>> - compiling with -fsanitize=address
>> everything works without problems here!
>> - compiling with ASSERTIONS=2
>> gave me this information:
>> [image: error.png]
>>
>> To me it looks like another resize call is executed while other workers
>> keep working on the buffer, and then something gets into conflict.
>> To test this, I allocated 1.8 GB right after startup in the main thread
>> and disposed the mem blocks again just to trigger heap resize. After that
>> everything works like a charm.
>>
>> Is there anything I am doing wrong?
>> Sorry for not providing a sample, but there is a lot of code involved,
>> and it is not easy to simulate this behavior. Happy to answer questions.
>>
>> All comments are appreciated.
>> Thanks,
>> Dieter
>>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/80d56314-59d8-4332-bb2e-ebe00fe52ea3n%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/80d56314-59d8-4332-bb2e-ebe00fe52ea3n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28J5-c7A2PmrUStwz1GtBD76djg5sPA76rM%3D%3DE5qe95qw%40mail.gmail.com.

Reply via email to