Skip to content

App is freezing in OffscreenCanvas.getContext("2d").getImageData ! #17130

@aharondavid

Description

@aharondavid

See the comment in the code below:

unsigned int futexVal = 0;

void* WakingThread(void* arg)
{
	Sleep(1000);
	using namespace emscripten;
	val offscreen = val::global("OffscreenCanvas").new_(256, 256);

	val context3 = offscreen.call<val>("getContext", std::string("2d"));

///////////////////////////////////////////////
  // After that line, the App freeze ! it seem to me a dead lock !
  // Without this line everything is ok.

      val imageData = context3.call<val>("getImageData", 0, 0, 50, 50);
/////////////////////////////////////////////////

``
	emscripten_atomic_store_u32(&futexVal, 1);
	emscripten_futex_wake(&futexVal, INT_MAX);

	pthread_exit(0);
}

// the main()  run in main thread
OnButton()
{        
        pthread_t thread;
	pthread_attr_t attr1;
	pthread_attr_init(&attr1);
	int rct = pthread_create(&thread, &attr1, (void* (*)(void*))WakingThread, nullptr);
	
	while (emscripten_atomic_load_u32(&futexVal) == 0)
	{
		emscripten_console_log("in __");
		emscripten_futex_wait(&futexVal, 0, INFINITY);
		emscripten_console_log("end __");
	}
}

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9 (54675ba)
clang version 15.0.0 (https://github.com/llvm/llvm-project faef447e72a5c63dfb12bb7b02d44c3c916d31cd)
Target: wasm32-unknown-emscripten
Thread model: posix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions