Skip to content
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

Multithread fix (#2) #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Multithread fix (#2) #3

wants to merge 2 commits into from

Conversation

s9105947
Copy link
Contributor

@s9105947 s9105947 commented Feb 6, 2024

Fixes #2.

Given there are no metrics to be recorded, no thread will be launched.
However, the final cleanup handler will still attempt to join a thread -- which then fails, as there is no thread.

This PR adds state tracking of the thread and only joins if a thread actually has been launched.

The fix for #1 relies on comparing pthread_t, which according to
pthread_equal(3) is not allowed.
This patch adds a variable thread_active which is 1 while the
measurement thread is active, and is 0 otherwise. This state is tracked
manually. This is required to avoid the attempt of joining a non-created
thread.

According to pthread_equal(3) it is not acceptable to directly compare
two pthread_t, as they should be considered opaque. Hence, external
tracking whether a thread is active is required. (For this reason, the
hacky solution of comparing to 0 is not used, also it would probably
work.)

This patch further adds error checking for the final thread join. On
error, errno is printed with a debug message.
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.

Race condition in fini()
2 participants