emscripten-core / emscripten-core/emscripten

SDL2 application will break when using pthreads

Open
#6,009 17 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I have made a SDL2 application using the linker flag "-s USE_SDL=2" which works as expected.
I have made a ASIO application using https://github.com/emscripten-ports/asio which works as expected.
I have made a ASIO/pthread application with works as expected using the linker flags "-s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -s PROXY_TO_PTHREAD=1"

But I can not merge these applications together. It seems as if USE_SDL and USE_PTHREADS/PROXY_TO_PTHREAD works against each other. I known that many older tutorials states that multithreading is not possible, but also knows that a lot of activities has been done to change this.

I get the following error when combining SDL and pthreads:
pthread-main.js onmessage() captured an uncaught exception: ReferenceError: screen is not defined

I can understand that I would make sense that the resources for rendering would only be available for the main thread, but pthread is missing some features/resources for SDL to possible.

Is it by design that USE_SDL and USE_PTHREADS/PROXY_TO_PTHREAD work against each other?
Would it be possible to use SDL from the main thread and still use pthreads for additional work?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.