Skip to content

Add more testing for pthread_kill.#26663

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:pthread_kill
Apr 10, 2026
Merged

Add more testing for pthread_kill.#26663
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:pthread_kill

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented Apr 9, 2026

  • Test using pthread_kill on yourself.
  • Test using pthread_kill from a background thread to the main thread. For some reason this was disallowed before.
  • Add a stub version of pthread_kill along with a test.

return EINVAL;
}
if (t == emscripten_main_runtime_thread_id()) {
if (sig == 0) return 0; // signal == 0 is a no-op.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this a perf optimization perhaps?

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.

Just simplifying the code a little.

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.

Oh.. also I'm removing this limitation. For some reason we were disallowing using pthread_kill to send signals to the main runtime thread.. I'm not sure why.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth a changelog mention perhaps, if this is a breaking change? Though maybe not if there are hardly any users of this.

Though I would suspect this limitation was there for a reason... maybe git history helps?

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.

This is very niche.. and its changing from non-standard + restrictive behavior to standard + less restrictive behaviour. I tend to think that moving things towards standard behaviour and removing restrictions normally mean less reason to add ChangeLog entry?

Copy link
Copy Markdown
Collaborator Author

@sbc100 sbc100 Apr 9, 2026

Choose a reason for hiding this comment

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

Looks like this was inherited from the JS version in #17041.

The JS version had "err('Main thread (id=' + ptrToString(thread) + ') cannot be killed with pthread_kill!');"

The "cannot be killed" message dates all the way back to 4f29d30 in 2015.

I imagine it was logical to thing that the main browser thread cannot be killed, but kill and also be used to send all kinds of signal. Its doesn't actaully kill anything necessarily.. confusing name. In any case raise (which is what kill really does) works fine on the main browser thread.

@sbc100 sbc100 force-pushed the pthread_kill branch 2 times, most recently from 969a8aa to cde49d9 Compare April 9, 2026 23:27
@sbc100 sbc100 requested a review from kripken April 9, 2026 23:30
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm % comment

@sbc100 sbc100 enabled auto-merge (squash) April 10, 2026 00:09
- Test using `pthread_kill` on yourself.
- Test using `pthread_kill` from a background thread to the main thread.
@sbc100 sbc100 merged commit 2cf3138 into emscripten-core:main Apr 10, 2026
27 checks passed
@sbc100 sbc100 deleted the pthread_kill branch April 10, 2026 00:53
sbc100 added a commit to sbc100/emscripten that referenced this pull request Apr 10, 2026
This special handling for SIGCANCEL should not be needed.

If we need to do something like `_emscripten_runtime_keepalive_clear`
during pthread cancelation it would be best done when the cancellation
in processed in `__testcancel`/`__cancel`.

The comment and code I'm removing here was added back in emscripten-core#22467 along
with testing in the form of `test/pthread/test_pthread_kill.c` and the
pthread_kill tests in posixtest.

I recently expanded the testing in emscripten-core#26663, and this change doesn't break
any of those tests.
sbc100 added a commit that referenced this pull request Apr 11, 2026
This special handling for `SIGCANCEL` should not be needed. If we need
to do something like `_emscripten_runtime_keepalive_clear` during
pthread cancelation it would be best done when the cancellation in
processed in `__testcancel`/`__cancel`.

The comment & code I'm removing here was added back in #22467 along with
testing in the form of `test/pthread/test_pthread_kill.c` and the
pthread_kill tests in posixtest.

I recently expanded the testing in #26663, and this change doesn't break
any of those tests.
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