Skip to content

Commit

Permalink
DAQSource (same change as in FedRawDataInputSource)
Browse files Browse the repository at this point in the history
- intialize vectors before spawning threads to avoid waiting on a
condition-variable thread that is part of a vector being expanded.
- remove synchronization point since creation of a thread already implies a memory barrier.
  • Loading branch information
smorovic committed May 14, 2023
1 parent cfbbed1 commit a2d9782
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion EventFilter/Utilities/interface/DAQSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class DAQSource : public edm::RawInputSource {
tbb::concurrent_queue<std::unique_ptr<RawInputFile>> fileQueue_;

std::mutex mReader_;
std::vector<std::condition_variable*> cvReader_;
std::vector<std::unique_ptr<std::condition_variable>> cvReader_;
std::vector<unsigned int> tid_active_;

std::atomic<bool> quit_threads_;
Expand Down
21 changes: 8 additions & 13 deletions EventFilter/Utilities/src/DAQSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ DAQSource::DAQSource(edm::ParameterSet const& pset, edm::InputSourceDescription

quit_threads_ = false;

//prepare data shared by threads
for (unsigned int i = 0; i < numConcurrentReads_; i++) {
std::unique_lock<std::mutex> lk(startupLock_);
//issue a memory fence here and in threads (constructor was segfaulting without this)
thread_quit_signal.push_back(false);
workerJob_.push_back(ReaderInfo(nullptr, nullptr));
cvReader_.push_back(new std::condition_variable);
cvReader_.push_back(std::make_unique<std::condition_variable>());
tid_active_.push_back(0);
threadInit_.store(false, std::memory_order_release);
}

//start threads
for (unsigned int i = 0; i < numConcurrentReads_; i++) {
//wait for each thread to complete initialization
std::unique_lock<std::mutex> lk(startupLock_);
workerThreads_.push_back(new std::thread(&DAQSource::readWorker, this, i));
startupCv_.wait(lk);
}
Expand Down Expand Up @@ -211,15 +215,6 @@ DAQSource::~DAQSource() {
delete workerThreads_[i];
}
}
for (unsigned int i = 0; i < numConcurrentReads_; i++)
delete cvReader_[i];
/*
for (unsigned int i=0;i<numConcurrentReads_+1;i++) {
InputChunk *ch;
while (!freeChunks_.try_pop(ch)) {}
delete ch;
}
*/
}

void DAQSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down

0 comments on commit a2d9782

Please sign in to comment.