Skip to content

Commit 3c8b6c2

Browse files
authored
Fix 2 uninitialized variables (#147)
* Code rewrite of swdsm_argo_barrier() to avoid unitialized variable New(er) compiler versions report that variable `barrierlockholder` may be used unitialized in this function. This was known for a while now, but our (local) fix was unsatisfactory and was therefore not pushed to the code base. Motivated by #146, which is also not perfect as a fix, we have decided to rewrite that code and eliminate the uses of this variable, paying some cost in (small) code duplication. Closes #146 Co-authored by: @davidklaftenegger * Initialize variable to suppress warning
1 parent 2207fbd commit 3c8b6c2

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/backend/mpi/swdsm.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,6 @@ void self_upgrade(argo::backend::upgrade_type upgrade) {
10231023
}
10241024

10251025
void swdsm_argo_barrier(int n, argo::backend::upgrade_type upgrade) {
1026-
pthread_t barrierlockholder;
10271026
double t1 = MPI_Wtime();
10281027

10291028
// Wait for n threads to arrive
@@ -1038,7 +1037,6 @@ void swdsm_argo_barrier(int n, argo::backend::upgrade_type upgrade) {
10381037

10391038
// Let one thread per node perform MPI operations
10401039
if(pthread_mutex_trylock(&barriermutex) == 0) {
1041-
barrierlockholder = pthread_self();
10421040
std::unique_lock lock(sync_lock);
10431041

10441042
// Perform SD followed by SI
@@ -1051,14 +1049,14 @@ void swdsm_argo_barrier(int n, argo::backend::upgrade_type upgrade) {
10511049
self_upgrade(upgrade);
10521050
MPI_Barrier(argo_comm);
10531051
}
1054-
}
1055-
1056-
// Wait for n threads to arrive
1057-
pthread_barrier_wait(&threadbarrier[n]);
1058-
if (pthread_equal(barrierlockholder, pthread_self())) {
1052+
// Wait for n threads to arrive
1053+
pthread_barrier_wait(&threadbarrier[n]);
10591054
pthread_mutex_unlock(&barriermutex);
10601055
stats.barriers++;
10611056
stats.barriertime += MPI_Wtime() - t1;
1057+
} else {
1058+
// For everybody else wait for n threads to arrive
1059+
pthread_barrier_wait(&threadbarrier[n]);
10621060
}
10631061
}
10641062

tests/lock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ constexpr std::size_t cache_size = size;
3131

3232
/** @brief number of threads to spawn for some of the tests */
3333
constexpr int nThreads = 16;
34-
/** @brief number of itereations to run for some of the tests */
34+
/** @brief number of iterations to run for some of the tests */
3535
constexpr int iter = 10000;
3636

3737
/**
@@ -74,7 +74,7 @@ class LockTest : public testing::Test {
7474
*/
7575
TEST_F(LockTest, TAS_trylock_all) {
7676
bool *did_increment;
77-
bool res;
77+
bool res = false;
7878
counter = argo::conew_<int>();
7979
did_increment = argo::conew_array<bool>(argo::number_of_nodes());
8080

0 commit comments

Comments
 (0)