Skip to content

Commit

Permalink
fix thread-count race condition during memory-manager init
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-auger committed May 2, 2020
1 parent 55424f8 commit b5eb233
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/fweelin_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,12 @@ template <class T> class SRMWRingBuffer : public RTDataStruct_Updater {

int WriteElement (const T &el) {
if (num_writers != RT_RWThreads::num_rw_threads) {
printf("CORE: ERROR: SRMWRingBuffer thread count mismatch.\n");
exit(1);
pthread_mutex_lock(&RT_RWThreads::register_rtstruct_lock);
pthread_mutex_unlock(&RT_RWThreads::register_rtstruct_lock);
if (num_writers != RT_RWThreads::num_rw_threads) {
printf("CORE: ERROR: SRMWRingBuffer thread count mismatch.\n");
exit(1);
}
}

// Determine which write thread we are
Expand All @@ -709,8 +713,12 @@ template <class T> class SRMWRingBuffer : public RTDataStruct_Updater {

const T ReadElement () {
if (num_writers != RT_RWThreads::num_rw_threads) {
printf("CORE: ERROR: SRMWRingBuffer thread count mismatch.\n");
exit(1);
pthread_mutex_lock(&RT_RWThreads::register_rtstruct_lock);
pthread_mutex_unlock(&RT_RWThreads::register_rtstruct_lock);
if (num_writers != RT_RWThreads::num_rw_threads) {
printf("CORE: ERROR: SRMWRingBuffer thread count mismatch.\n");
exit(1);
}
}

// Check each ring buffer
Expand Down

0 comments on commit b5eb233

Please sign in to comment.