Name pthread workers for easier debugging
This is a feature suggestion.
Workers accept an optional name which can be used for debugging, e.g. in DevTools we show the name in the Sources panel.

The name is also available to the worker via globalThis.name.
My suggestion is that in src/library_pthread.js, in allocateUnusedWorker when we call new Worker(), we give a useful name like pthread #1 etc.
Right now threads just show up with the file name (which also means all the threads have the same name).
Nice. We could also support https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html ?
I would like to implement this feature!
It looks like we already have emscripten_set_thread_name in the public C API and then we have PThread.getThreadName and PThread.setThreadName in the JS API.
However it doesn't look like we set globalThis.name based on this name.
On simple thing to do would be to set globalThis.name during PThread.setThreadName if the name is being set for the current thread. If the name is being set of a different thread is a little more tricky.. we would need to set a message to that thread to change its own name.
We could also add pthread_setname_np as a more standard way to set the name, rather than the emscripten-specific emscripten_set_thread_name
Has this issue been resolved?
@sabtt17 I don't think work has been done here - it's free to work on.
Adding a simple name to new Worker would be a good start. @sbc100 's additional suggestions are also worth doing but those could be separate.
I started working on this, but I haven't been able to run pthread tests locally. After running ./tests/runner.py pthread, I keep getting:
ERROR: could not find the following tests: pthread
even though the directory exists, and running the same command with browser works fine. Could this be a problem with my installation?
@sabtt17
Tests need to be run with their full name, which starts with test_. For example, ./tests/runner.py test_pthread_create will run the test with that specific name. Wildcards also work, so many of the pthreads tests can be run with ./tests/runner.py test_pthread* (for the shell versions) or ./tests/runner.py browser.test_pthread* (for the browser versions).
The reason ./tests/runner.py browser works is that "browser" is an entire suite of tests; browser is the same as browser.*, but there isn't a separate suite for pthreads. (Browser tests have their own suite because they are run very differently than shell tests - we spin up a browser and a webserver etc.)
Thanks! That worked!
FYI the debugging story for naming web workers isn't all in place yet for this feature request to really work (in either Chrome, FF or Safari), but I've kicked off discussion of it with the Chrome DevTools folks.
I just also stumbled across this, when the linker complained that it wasn't able to find pthread_setname_np .
I now replaced it with the emscripten_set_thread_name and just hope that it will work somehow, but it would be nice if the standard API could be supported in the future.
But this could probably wait until support from browser vendors is really there.
Is it straightforward to implement pthread_getname_np? I was compiling emilk/loguru with emscripten and ran into an undefined symbol error for pthread_getname_np
Sadly neither FF or chrome support changing the name of a thread after its created. Chrome will show the name of thread, but it is currently fixed at thread creation time. So I don't think we can fix this until https://github.com/whatwg/html/issues/7838 is resolved.