LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Workqueue Depth (https://www.linuxquestions.org/questions/linux-software-2/workqueue-depth-4175503264/)

amitragarwal 04-28-2014 03:53 PM

Workqueue Depth
 
Hi,
I am trying to use workqueue to handled shared buffer in multi process system. Any process can come in and queue the work which can be processed in sequential order in worker thread. Semaphores don't help because they starve higher priority thread in such scenario.

The question is what is the depth of a workqueue? I see linked list implementation but how do I know when to limit processes to queue more work on this wq? If I don't limit them, the system is very unstable.

Thanks

sundialsvcs 04-28-2014 08:27 PM

One way to do this, with POSIX semaphores, is to initialize a semaphore to a value equal to the maximum buffer-depth you want. A process wishing to add an entry must first sem_wait() on a semaphore which contains this count. It then is entitled to add an entry to the queue, which action is controlled by another (this time, binary) semaphore. The consumer process that removes entries from the buffer then issues a sem_post() against the count semaphore to allow processes that are waiting for permission to post a new entry to do so.

Notice there are two semaphores. One, with a count, controls the size of the buffer. The second, binary, secures the shared data-structure itself.


All times are GMT -5. The time now is 07:24 AM.