Skip to content

How to import test.js(test.worker.js and test.wasm) in webworker #17048

Description

@yangfangfang1204

in c code ,i create a pthread ,and generate the test.js ,test.worker.js and test.wasm by emscripten.

and in WebWorker, i need import the test.js ,so how can i import it .

the demo.html :
`<!doctype html>

start stop
<script> var worker2 = null; function init() { //Module._test();
	worker2 = new Worker('./bitmap_worker.js');

	////向worker传递信息
	worker2.onmessage = function (e) {
		if(e.data.name==="loaded")
		{
			worker2.postMessage({name:"test"});
		}
		
	}
}
function stop()
{
    worker2.terminate();  // 停止 Worker 工作
    worker2 = null;
	console.log("stop worker!!!!");
}
</script> `

the bitmap_worker.js :
`'use strict';
importScripts("testThread.js");
Module.addOnPostRun(function () {
postMessage({'name': "loaded"});
});

var offscreen,ctx,gl;

onmessage = function (e) {
if(e.data.name == 'test'){
console.log('>>>>Worker test 11');
test();
postMessage({'name': "testRes", 'res': 1});
}
}

function test()
{
Module._test();
}

And the compile isemcc -O3 testThread.cpp -o testThread.js -s PTHREAD_POOL_SIZE=2 -s USE_PTHREADS=1 -s "EXPORTED_RUNTIME_METHODS=['addOnPostRun']" -s EXPORTED_FUNCTIONS="['_test','_stop']" -s TOTAL_MEMORY=128MB -s ENVIRONMENT='worker'`

the pthread in c code can not run ?

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