Skip to content

Don't call emscripten_tls_init from static constructor. NFC #14981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2021

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Aug 31, 2021

This change makes handling of emscripten_tls_init the
same on all threads, including the main thread and/or library
loading thread.

This is precursor to a change that makes use of the return
value of emscripten_tls_init to do TLS relocations so making
the call explicit is required.

@sbc100 sbc100 requested a review from tlively August 31, 2021 16:02
@sbc100 sbc100 force-pushed the tls_init_no_ctor branch 4 times, most recently from 5623ed5 to 14b3503 Compare August 31, 2021 16:25
This change makes handling of `emscripten_tls_init` the
same on all threads, including the main thread and/or library
loading thread.

This is precursor to a change that makes use of the return
value of emscripten_tls_init to do TLS relocations so making
the call explicit is required.

I've also removed the use of EM_ASM from library_pthread.c.
#if PTHREADS_PROFILING
PThread.createProfilerBlock(tb);
PThread.setThreadName(tb, "Browser main thread");
PThread.setThreadStatus(tb, {{{ cDefine('EM_THREAD_STATUS_RUNNING') }}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need to set the thread status any more down in __emscripten_init_main_thread_js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added call to PThread.threadInit which takes case of setThreadStatus. Before threadInit was only called on threads. Now its called on the main thread too (during __emscripten_init_main_thread_js).

Comment on lines +495 to +498
PThread.tlsInitFunctions.push(initTLS);
if (runtimeInitialized) {
initTLS();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this pushes and calls initTLS whether or not we are in a pthread, but previously both only happened when not in a pthread. Why is this change correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the main thread would run its TLS inits from the static ctor, but the threads would need to run this explicitly. The point of this change is to remove this difference and always run init TLS explicitly.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

@sbc100 sbc100 merged commit 85d58ff into main Aug 31, 2021
@sbc100 sbc100 deleted the tls_init_no_ctor branch August 31, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants