Skip to content
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

Merged
merged 3 commits into from Nov 4, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions L1Trigger/CSCTriggerPrimitives/src/CSCCathodeLCTProcessor.cc
Expand Up @@ -243,7 +243,7 @@ CSCCathodeLCTProcessor::CSCCathodeLCTProcessor(unsigned endcap,
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};
Copy link
Contributor

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.


// CLCT configuration parameters.
fifo_tbins = conf.getParameter<unsigned int>("clctFifoTbins");
Expand Down Expand Up @@ -359,7 +359,7 @@ CSCCathodeLCTProcessor::CSCCathodeLCTProcessor() :
theEndcap(1), theStation(1), theSector(1),
theSubsector(1), theTrigChamber(1) {
// constructor for debugging.
static bool config_dumped = false;
static std::atomic<bool> config_dumped{false};

// CLCT configuration parameters.
setDefaultConfigParameters();
Expand Down Expand Up @@ -419,7 +419,7 @@ void CSCCathodeLCTProcessor::setDefaultConfigParameters() {

// Set configuration parameters obtained via EventSetup mechanism.
void CSCCathodeLCTProcessor::setConfigParameters(const CSCDBL1TPParameters* conf) {
static bool config_dumped = false;
static std::atomic<bool> config_dumped{false};

fifo_tbins = conf->clctFifoTbins();
fifo_pretrig = conf->clctFifoPretrig();
Expand Down Expand Up @@ -552,7 +552,7 @@ CSCCathodeLCTProcessor::run(const CSCComparatorDigiCollection* compdc) {

// clear(); // redundant; called by L1MuCSCMotherboard.

static bool config_dumped = false;
static std::atomic<bool> config_dumped{false};
if ((infoV > 0 || isSLHC) && !config_dumped) {
//std::cerr<<"**** CLCT run parameters dump ****"<<std::endl;
dumpConfigParams();
Expand Down Expand Up @@ -1017,7 +1017,7 @@ void CSCCathodeLCTProcessor::readComparatorDigis(
// This loop is only for distrips. We have to separate the routines
// because triad and time arrays can be changed by the distripStagger
// routine which could mess up the halfstrips.
static int test_iteration = 0;
static std::atomic<int> test_iteration{0};
for (int j = 0; j < CSCConstants::MAX_NUM_STRIPS; j++){
if (time[i][j] >= 0) {
int i_distrip = j/2;
Expand Down Expand Up @@ -2232,7 +2232,7 @@ void CSCCathodeLCTProcessor::pulseExtension(
const int nStrips,
unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]) {

static unsigned int bits_in_pulse = 8*sizeof(pulse[0][0]);
static const unsigned int bits_in_pulse = 8*sizeof(pulse[0][0]);

// Clear pulse array. This array will be used as a bit representation of
// hit times. For example: if strip[1][2] has a value of 3, then 1 shifted
Expand Down Expand Up @@ -2824,11 +2824,12 @@ std::vector<CSCCLCTDigi> CSCCathodeLCTProcessor::readoutCLCTs() {
// tmb_l1a_window_size parameter, but made even by setting the LSB
// of tmb_l1a_window_size to 0.
//
static int lct_bins =
(tmb_l1a_window_size%2 == 0) ? tmb_l1a_window_size : tmb_l1a_window_size-1;
static int late_tbins = early_tbins + lct_bins;
static std::atomic<int> lct_bins;
lct_bins = (tmb_l1a_window_size%2 == 0) ? tmb_l1a_window_size : tmb_l1a_window_size-1;
static std::atomic<int> late_tbins;
late_tbins = early_tbins + lct_bins;

static int ifois = 0;
static std::atomic<int> ifois{0};
if (ifois == 0) {
if (infoV >= 0 && early_tbins < 0) {
edm::LogWarning("L1CSCTPEmulatorSuspiciousParameters")
Expand Down