-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
thread safety statics work … #1294
thread safety statics work … #1294
Conversation
changed static to static const where possible otherwise used std::atomic<> when value is set once then read.
A new Pull Request was created by @gartung (Patrick Gartung) for CMSSW_7_0_X. thread safety statics work It involves the following packages: L1Trigger/CSCTriggerPrimitives @nclopezo, @mulhearn can you please review it and eventually sign? Thanks. |
@@ -243,7 +243,7 @@ | |||
const edm::ParameterSet& ctmb) : | |||
theEndcap(endcap), theStation(station), theSector(sector), | |||
theSubsector(subsector), theTrigChamber(chamber) { | |||
static bool config_dumped = false; | |||
static std::atomic<bool> config_dumped{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking further in the code, the use of std::atomic<bool>
isn't proper since it still allows multiple threads to do the 'initail' work. To make it only one thread one changes
if(... !config_dumped) {
...
config_dumped = true;
}
to
bool expected = false;
if(... config_dumped.compare_exchange_strong(false,true, std::memory_order_acq_rel) ) {
...
}
There is no need for a later config_dumped=true
since the compare_exchange_strong
will set it to true
for the first thread to hit that line.
NOTE: this only works if the body of work in the if(...) { }
block doesn't do any work needed by the algorithm after that block. If it does, then we'd have to use std::call_once(...)
instead.
+1 |
+1 |
This pull request is fully signed and it will be integrated in one of the next IBs unless changes or unless it breaks tests. @ktf can you please take care of it? |
…mitives Multithreading fixes -- Remove statics in L1Trigger/CSCTriggerPrimitives
changed static to static const where possible otherwise used std::atomic<> when value is changed once