How can I synchronize three threads?

后端 未结 6 1831
北恋
北恋 2021-01-16 10:44

My app consist of the main-process and two threads, all running concurrently and making use of three fifo-queues:

The fifo-q\'s are Qmain, Q1 and Q2. Internally the

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 11:30

    Are you acquiring multiple locks simultaneously? This is generally something you want to avoid. If you must, ensure you are always acquiring the locks in the same order in each thread (this is more restrictive to your concurrency and why you generally want to avoid it).

    Other concurrency advice: Are you acquiring the lock prior to reading the queue sizes? If you're using a mutex to protect the queues, then your queue implementation isn't concurrent and you probably need to acquire the lock before reading the queue size.

提交回复
热议问题