Skip to content

Commit

Permalink
Merge pull request #369 from JeffersonLab/rasool_jana2.3.2
Browse files Browse the repository at this point in the history
Fix for Lock Overwrite Issue in Multithreaded RootFillLock Handling
  • Loading branch information
nathanwbrei authored Oct 10, 2024
2 parents 3a9c913 + 1a41aff commit 38c0e9a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libraries/JANA/CLI/JBenchmarker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void JBenchmarker::RunUntilFinished() {
<< " cd " << m_output_dir << "\n"
<< " $JANA_HOME/bin/jana-plot-scaletest.py\n" << LOG_END;
}
m_app->Stop();
m_app->Stop(true);
}


Expand Down
3 changes: 3 additions & 0 deletions src/libraries/JANA/Calibrations/JCalibrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class JCalibrationManager : public JService {
public:

JCalibrationManager() {
pthread_mutex_init(&m_calibration_mutex, nullptr);
pthread_mutex_init(&m_resource_manager_mutex, nullptr);

SetPrefix("jana");
}

Expand Down
15 changes: 10 additions & 5 deletions src/libraries/JANA/Compatibility/JLockService.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,22 @@ inline pthread_rwlock_t *JLockService::RootFillLock(JEventProcessor *proc) {
/// are in use and all contending for the same root lock. You should
/// only use this when filling a histogram and not for creating. Use
/// RootWriteLock and RootUnLock for that.

pthread_rwlock_t *lock;

pthread_rwlock_rdlock(&m_root_fill_locks_lock);
auto iter = m_root_fill_rw_lock.find(proc);
if (iter == m_root_fill_rw_lock.end()) {
pthread_rwlock_unlock(&m_root_fill_locks_lock);
lock = new pthread_rwlock_t;
pthread_rwlock_wrlock(&m_root_fill_locks_lock);
pthread_rwlock_init(lock, nullptr);
m_root_fill_rw_lock[proc] = lock;
auto iter_now = m_root_fill_rw_lock.find(proc);
if(iter_now == m_root_fill_rw_lock.end()){
lock = new pthread_rwlock_t;
pthread_rwlock_init(lock, nullptr);
m_root_fill_rw_lock[proc] = lock;
}
else{
lock = iter_now->second;
}
}
else {
lock = iter->second;
Expand Down Expand Up @@ -265,7 +270,7 @@ inline pthread_rwlock_t *JLockService::RootFillUnLock(JEventProcessor *proc) {
}
pthread_rwlock_t *lock = iter->second;
pthread_rwlock_unlock(&m_root_fill_locks_lock);
pthread_rwlock_unlock(m_root_fill_rw_lock[proc]);
pthread_rwlock_unlock(lock);
return lock;
}

Expand Down

0 comments on commit 38c0e9a

Please sign in to comment.