Category : concurrency

Description I have a serial connection object, _serial, that facilitates sending / receiving RS232 commands. There is one function, sendCommand, that sends data via the serial object. There is one function, serialProducer, that reads data via the serial object. I have to class mutexes, _readMtx and _writeMtx. Since RS232 can asynchronously read / write, there ..

Read more

I have this code: std::map<std::pair<int, int>, std::string> data; … ContextMutex context_mutex( _mutex ); auto pair_iterator = data.find( std::make_pair(some, thing)); if(pair_iterator == data.end()) { context_mutex.unlock(); // do some logging without using pair_iterator } context_mutex.unlock(); On this code, I only release the mutex for my STL container after checking if pair_iterator == data.end(). I wonder if I ..

Read more

#include <iostream> #include <vector> #include <array> #include <random> #include <ranges> #include <cmath> #include <limits> #include <thread> #include <functional> #include "ChiliTimer.h" /* size_t = unsigned integer */ constexpr size_t DATASET_SIZE = 100; void ProcessDataset(std::array<int,DATASET_SIZE>& set ) { for (int x : set) { constexpr auto limit = (double)std::numeric_limits<int>::max(); const auto y = (double)x / limit; set[0] ..

Read more

I’m new to concurrent programming and I’m trying to compile the following code: private: std::atomic<bool> resizing_; void Resize() { if (resizing_.compare_exchange_strong(false, true)… } This throws error: no matching member function for call to ‘compare_exchange_strong’ and I’m not sure how I can fix this. I’ve tried using a bool* for the first argument but that didn’t ..

Read more