How can I synchronize three threads?

后端 未结 6 1833
北恋
北恋 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:22

    You should not lock second mutex when you already locked one.

    Since the question is tagged with C++, I suggest to implement locking inside get/add logic of the queue class (e.g. using boost locks) or write a wrapper if your queue is not a class.

    This allows you to simplify the locking logic.

    Regarding the sources you have added: queue size check and following put/get should be done in one transaction otherwise another thread can edit the queue in between

提交回复
热议问题