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

Use valid address in pthread_setspecific to silence warnings #162

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion thread_setup_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ static pthread_mutex_t *mutex_buf = NULL;

static pthread_key_t destructor_key;

/* Used in pthread_setspecific. See https://github.com/microsoft/go/issues/1305. */
qmuntal marked this conversation as resolved.
Show resolved Hide resolved
static char stub;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to exist at the global scope, or could static char stub; or char stub; be declared just before the call?

If there's no difference, I think putting the declaration inside thread_id would be a bit clearer. And IMO putting it on the stack (if possible) raises the fewest questions from a reader's perspective. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks putting the variable in the function scope also works, and it does look clearer. I'll keep the static keyword, though, I would rather not pass a pointer to a stack-allocated variable that can be used outside the function frame, just in case it is used somewhere 😅.


/* Used by unit tests. */
volatile unsigned int go_openssl_threads_cleaned_up = 0;

Expand All @@ -29,7 +32,7 @@ static void thread_id(GO_CRYPTO_THREADID_PTR tid)
// least once on any thread with associated error state. The thread-local
// variable needs to be set to a non-NULL value so that the destructor will
// be called when the thread exits. The actual value does not matter.
(void) pthread_setspecific(destructor_key, (void*)1);
(void) pthread_setspecific(destructor_key, &stub);
karianna marked this conversation as resolved.
Show resolved Hide resolved
}

static void cleanup_thread_state(void *ignored)
Expand Down
Loading