Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion system/lib/pthread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,20 @@ void _emscripten_thread_free_data(pthread_t t) {
emscripten_builtin_free(t->profilerBlock);
}
#endif
// Clear the self-reference to prevent inadvertent use and
// inform functions that validate it that the thread is no
// longer available.
t->self = NULL;

// Free all the entire thread block (called map_base because
// Free the entire thread block (called map_base because
// musl normally allocates this using mmap). This region
// includes the pthread structure itself.
unsigned char* block = t->map_base;
dbg("_emscripten_thread_free_data thread=%p map_base=%p", t, block);
#ifndef NDEBUG
// To aid in debugging, set the entire region to zero.
memset(block, 0, sizeof(struct pthread));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it not useful for debugging to reset this memory to something ? Maybe 0xfe ? Maybe only in debug builds?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Commit e206e45 does this only for debug builds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we actually use 0xdd (or some other recognizable value) rather than zero?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, but I think that would break the ->tid check in _emscripten_thread_is_valid().

#endif
emscripten_builtin_free(block);
}

Expand Down
9 changes: 4 additions & 5 deletions test/codesize/test_codesize_minimal_pthreads.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7372,
"a.out.js.gz": 3593,
"a.out.nodebug.wasm": 19047,
"a.out.nodebug.wasm.gz": 8796,
"total": 26419,
"total_gz": 12389,
"a.out.nodebug.wasm": 19037,
"a.out.nodebug.wasm.gz": 8786,
"total": 26409,
"total_gz": 12379,
"sent": [
"a (memory)",
"b (exit)",
Expand Down Expand Up @@ -62,7 +62,6 @@
"funcs": [
"$__errno_location",
"$__memcpy",
"$__memset",
"$__pthread_getspecific",
"$__pthread_mutex_lock",
"$__pthread_mutex_trylock",
Expand Down
9 changes: 4 additions & 5 deletions test/codesize/test_codesize_minimal_pthreads_memgrowth.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7781,
"a.out.js.gz": 3797,
"a.out.nodebug.wasm": 19048,
"a.out.nodebug.wasm.gz": 8797,
"total": 26829,
"total_gz": 12594,
"a.out.nodebug.wasm": 19038,
"a.out.nodebug.wasm.gz": 8787,
"total": 26819,
"total_gz": 12584,
"sent": [
"a (memory)",
"b (exit)",
Expand Down Expand Up @@ -62,7 +62,6 @@
"funcs": [
"$__errno_location",
"$__memcpy",
"$__memset",
"$__pthread_getspecific",
"$__pthread_mutex_lock",
"$__pthread_mutex_trylock",
Expand Down
Loading