JeffersonLab / JANA2

Multi-threaded HENP Event Reconstruction
https://jeffersonlab.github.io/JANA2/
Other
6 stars 9 forks source link

Fix for Lock Overwrite Issue in Multithreaded RootFillLock Handling #369

Closed RaiqaRasool closed 1 month ago

RaiqaRasool commented 1 month ago

The issue occurs when multiple threads call RootFillLock. Each thread was independently creating its own lock and overriding the lock saved by the previous thread in m_root_fill_rw_lock. This resulted in only the last thread's lock being retained. When RootFillUnlock was invoked, all threads attempted to unlock the lock acquired by the last thread, leading to undefined behavior due to multiple unlock operations on the same lock.

Resolution:

To address this, an additional check is added after acquiring the write lock. If the lock for the event processor (proc) has already been initialized by another thread, that lock will be used. This prevents each thread from initializing a new lock and ensures that only one lock is used across threads.

faustus123 commented 1 month ago

Line 236 introduces a small memory leak. The lock object should not be instantiated until inside the if-block that saves it.

RaiqaRasool commented 1 month ago

Line 236 introduces a small memory leak. The lock object should not be instantiated until inside the if-block that saves it.

Corrected!