Is there a way to ensure that threads are assigned to a specified set of objects?

后端 未结 5 681
旧时难觅i
旧时难觅i 2021-02-06 01:38

We are working on an application where a set of objects can be affected by receiving messages from 3 different sources. Each message (from any of the sources) has a single objec

5条回答
  •  不知归路
    2021-02-06 02:12

    My answers are:

    • 1 - yes
    • 2 -
      • a) No
      • b) you don't need to

    Some explanations:

    • you want one task to distribute messages to different queues according to some algorithm,
    • You want one task per message queue to pull messages from its assigned queue and process them.

    I don't think that these premises are contradicting the purpose of the ThreadPool, which is just about associating tasks to threads. In this model though, the Threadpool would associate threads to tasks only once, and then threads would keep running to poll their input message queue.

    The friction spots of the threads should be the intermediate messages queues, and perhaps other resources related to the processing of these messages. Following your explanations, I suppose that you plan to reduce the second kind to a minimum by cleverly partitioning the message processing to the tasks. Each queue should only be accessed by the partitioning task and the processing task associated to the queue, so it should be minimal.

提交回复
热议问题