Closed Zzzen closed 4 years ago
That function should arrive from loading the main JS code, by that worker.js file. Not sure offhand what could break that, but I'd start by checking if there are warnings in the devtools (did a file fail to load, etc.). If that's not it, building a hello world that creates a pthread can give you a working testcase (can look in the test suite for test_pthread*
for examples, and compare that to what you have to look for differences.
__register_pthread_ptr
is not defined inworker.js
Hi @Zzzen, have you resolved the problem about '__register_pthread_ptr is not defined in worker.js'?
I get the same exception when using -s MODULARIZE_INSTANCE=1
in combination with -s EXPORT_NAME=MyModule
. Here is a test case that reproduces this problem:
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 1111111..2222222 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -3701,6 +3701,7 @@ window.close = function() {
test([])
test(['-O3'])
test(['-s', 'MODULARIZE_INSTANCE=1'])
+ test(['-s', 'MODULARIZE_INSTANCE=1', '-s', 'EXPORT_NAME=MyModule', '--shell-file', path_from_root('tests', 'shell_that_launches_modularize.html')])
# Test that preallocating worker threads work.
@requires_threads
@kleisauke
I think that shell file is only compatible with MODULARIZE
- it creates an instance - and not MODULARIZE_INSTANCE
. It works with the _INSTANCE
removed.
(Or have I missed the point here? Sorry if so.)
I used that shell file to hide this error:
shared:ERROR: Customizing EXPORT_NAME requires that the HTML be customized to use that name
(I've added -s EXPORT_NAME=MyModule
for reproducing this error, without that flag it runs correctly)
Here is a slightly improved test case (with a workaround):
# Test that basic thread creation works in combination with MODULARIZE_INSTANCE=1 and EXPORT_NAME=MyModule
@requires_threads
def test_pthread_modularize_export_name(self):
def test(args, workaround=None):
print(args)
print(('without' if workaround is None else 'with') + ' workaround')
self.btest(path_from_root('tests', 'pthread', 'test_pthread_create.cpp'), expected='0', args=['-s', 'TOTAL_MEMORY=64MB', '-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=8'] + args, post_build=workaround)
# we need to replace all Module instances with EXPORT_NAME as workaround
def workaround(*args):
worker = open('test.worker.js').read()
worker = worker.replace('Module = {};', 'MyModule = {}')
worker = worker.replace('Module[\'', 'MyModule[\'')
worker = worker.replace('global.Module = Module', 'global.MyModule = MyModule')
worker = worker.replace('out(', 'console.log(') # out is not defined for some reason? (this also fixes the warnings within test_pthread_create)
create_test_file('test.worker.js', worker)
create_test_file('shell.html', '''
<body>
{{{ SCRIPT }}}
</body>
''')
test(['-s', 'MODULARIZE_INSTANCE=1', '-s', 'EXPORT_NAME=MyModule', '--shell-file', 'shell.html'], workaround)
test(['-s', 'MODULARIZE_INSTANCE=1', '-s', 'EXPORT_NAME=MyModule', '--shell-file', 'shell.html'], None)
Thanks @kleisauke ! Great testcase, fix in #10449.
I was trying to build a multithreaded ffmpeg. But the generated worker.js doesn't work. Apparently,
__register_pthread_ptr
is not defined inworker.js
.you can download https://github.com/Zzzen/videoconverter.js/tree/test and try
generated worker.js