mutex

Map with concurrent access

a 夏天 提交于 2019-12-17 06:32:04
问题 When you use a map in a program with concurrent access, is there any need to use a mutex in functions to read values? 回答1: Multiple readers, no writers is okay: https://groups.google.com/d/msg/golang-nuts/HpLWnGTp-n8/hyUYmnWJqiQJ One writer, no readers is okay. (Maps wouldn't be much good otherwise.) Otherwise, if there is at least one writer and at least one more either writer or reader, then all readers and writers must use synchronization to access the map. A mutex works fine for this. 回答2

Lock, mutex, semaphore… what's the difference?

亡梦爱人 提交于 2019-12-17 04:36:14
问题 I've heard these words related to concurrent programming, but what's the difference between them? 回答1: A lock allows only one thread to enter the part that's locked and the lock is not shared with any other processes. A mutex is the same as a lock but it can be system wide (shared by multiple processes). A semaphore does the same as a mutex but allows x number of threads to enter, this can be used for example to limit the number of cpu, io or ram intensive tasks running at the same time. For

Is it smart to replace boost::thread and boost::mutex with c++11 equivalents?

↘锁芯ラ 提交于 2019-12-17 03:22:09
问题 Motivation: reason why I'm considering it is that my genius project manager thinks that boost is another dependency and that it is horrible because "you depend on it"(I tried explaining the quality of boost, then gave up after some time :( ). Smaller reason why I would like to do it is that I would like to learn c++11 features, because people will start writing code in it. So: Is there a 1:1 mapping between #include<thread> #include<mutex> and boost equivalents? Would you consider a good idea

Is it smart to replace boost::thread and boost::mutex with c++11 equivalents?

99封情书 提交于 2019-12-17 03:22:09
问题 Motivation: reason why I'm considering it is that my genius project manager thinks that boost is another dependency and that it is horrible because "you depend on it"(I tried explaining the quality of boost, then gave up after some time :( ). Smaller reason why I would like to do it is that I would like to learn c++11 features, because people will start writing code in it. So: Is there a 1:1 mapping between #include<thread> #include<mutex> and boost equivalents? Would you consider a good idea

Calling pthread_cond_signal without locking mutex

寵の児 提交于 2019-12-17 02:18:31
问题 I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutext after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another thread which is waiting on the condition variable. It should be called after mutex is locked, and must unlock mutex in order for pthread_cond_wait() routine to complete. My question is: isn't it OK to call pthread_cond_signal or pthread_cond_broadcast methods without locking the mutex? 回答1: If you do

Calling pthread_cond_signal without locking mutex

陌路散爱 提交于 2019-12-17 02:18:20
问题 I read somewhere that we should lock the mutex before calling pthread_cond_signal and unlock the mutext after calling it: The pthread_cond_signal() routine is used to signal (or wake up) another thread which is waiting on the condition variable. It should be called after mutex is locked, and must unlock mutex in order for pthread_cond_wait() routine to complete. My question is: isn't it OK to call pthread_cond_signal or pthread_cond_broadcast methods without locking the mutex? 回答1: If you do

Uart dma receive interrupt stops receiving data after several minutes

删除回忆录丶 提交于 2019-12-14 03:16:10
问题 I have a project that I have used stm32f746g discovery board. It receives data with fixed size from Uart sequentially and to inform application about each data receive completed, dma callback is used (HAL_UART_RxCpltCallback function). It works fine at the beginning but after several minutes of running, the dma callback stops to be called, and as a result, the specified parameter value doesn't get updated. Because the parameter is used in another thread too (actually a rtos defined timer), I

C++ undefined reference (static member) [duplicate]

时间秒杀一切 提交于 2019-12-14 02:43:24
问题 This question already has answers here : static variable link error (2 answers) Closed 4 years ago . Possible Duplicate: C++: undefined reference to static class member Logger.h: class Logger { private: Logger(); static void log(const string& tag, const string& msg, int level); static Mutex mutex; public: static void fatal(const string&, const string&); static void error(const string&, const string&); static void warn(const string&, const string&); static void debug(const string&, const

Maximizing Worker Thread Utilization

谁说我不能喝 提交于 2019-12-14 02:32:57
问题 To solve a problem (and better my understanding of multitasking) I have written a small thread pool implementation. This thread pool spins up a number of worker threads which pop tasks off of a queue as they are added by the client of the thread pool. For the purposes of this question when the task queue is empty the worker threads are all terminated. After doing some basic benchmarking I have discovered the application spends ~60% of its time waiting to acquire the queue lock. Presumably

How to unlock boost::upgrade_to_unique_lock (made from boost::shared_mutex)?

旧时模样 提交于 2019-12-14 01:28:41
问题 So I had some shared_mutex and done this: boost::upgrade_lock<boost::shared_mutex> lock(f->mutex); boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock); now I want to "unlock it" or at least downgrade it to something like: boost::shared_lock<boost::shared_mutex> lock_r(f->mutex); How to do such thing? Is it possible? 回答1: If you let the upgrade_to_unique_lock go out of scope, it will automatically downgrade back to upgrade ownership. For example void foo() { boost::upgrade_lock