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

Possible data race in src/posix/pthread.cpp #2200

Closed
mfbalin opened this issue Mar 22, 2020 · 4 comments
Closed

Possible data race in src/posix/pthread.cpp #2200

mfbalin opened this issue Mar 22, 2020 · 4 comments

Comments

@mfbalin
Copy link

mfbalin commented Mar 22, 2020

Inside pthread_create, static int thread_id = 0 increments each time a new thread is created, and it is not atomic, possibly causing a data race.

@fwsGonzo
Copy link
Member

fwsGonzo commented Mar 22, 2020

Not saying you are wrong here because there IS a race inside my threads implementation, but are you sure about this? Because I'm incrementing using:

  inline long generate_new_thread_id() noexcept {
	  return __sync_fetch_and_add(&thread_counter, 1);
  }

So, regardless of the counter itself, the source of new IDs is an atomic add.

@mfbalin
Copy link
Author

mfbalin commented Mar 22, 2020

static int __thread_id__ = 0;
auto new_id = __thread_id__++;

This is what I see on line 16.

@fwsGonzo
Copy link
Member

fwsGonzo commented Mar 22, 2020

Oh yes, I thought you meant src/kernel/threads.cpp. No, we don't use that anymore - it should have been deleted. We get pthreads from musl now.

https://github.com/includeos/IncludeOS/blob/master/src/musl/CMakeLists.txt

The file isn't in the build list.

@mfbalin
Copy link
Author

mfbalin commented Mar 22, 2020

Alright, thanks. I was glancing over the code and thought maybe I should open an issue about this.

@mfbalin mfbalin closed this as completed Mar 22, 2020
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

No branches or pull requests

2 participants