Skip to content

Conversation

@lucab
Copy link
Owner

@lucab lucab commented Jan 4, 2022

This adds a new PR_GET_NR_THREADS flag to prctl(2), which directly
exposes to userspace the thread-count from signal_struct.

It allows a calling process to self-introspect its own state and
detect whether it is currently executing in a single or
multi-threaded way.

This additional primitive is relevant for all those kinds of logic
which may not be safe or sound to execute in a multi-threaded
process (e.g. POSIX MT-Unsafe, setns(2) limitations, and more).

In particular, it caters to libraries which need to perform
such introspection in an efficient way and without having to resort
to procfs access (which may not be available, and additionally
requires FD-opening plus counting/parsing steps).

Signed-off-by: Luca BRUNO lucab@lucabruno.net

This adds a new PR_GET_NR_THREADS flag to prctl(2), which directly
exposes to userspace the thread-count from signal_struct.

It allows a calling process to self-introspect its own state and
detect whether it is currently executing in a single or
multi-threaded way.

This additional primitive is relevant for all those kinds of logic
which may not be safe or sound to execute in a multi-threaded
process (e.g. POSIX MT-Unsafe, setns(2) limitations, and more).

In particular, it caters to libraries which need to perform
such introspection in an efficient way and without having to resort
to procfs access (which may not be available, and additionally
requires FD-opening plus counting/parsing steps).

Signed-off-by: Luca BRUNO <lucab@lucabruno.net>
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