Closed mfbalin closed 4 years ago
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.
static int __thread_id__ = 0;
auto new_id = __thread_id__++;
This is what I see on line 16.
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.
Alright, thanks. I was glancing over the code and thought maybe I should open an issue about this.
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.