Queue blocking for producer / consumer threads for win32 / C

I am trying to replace some thread binding with a user queue, the producer is currently using PostThreadMessage, the consumer is using WaitForSingleObject / PeekMessage.

http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html will be what I need, but boost, and C ++ is not an option.

Not wanting to redefine the wheel, does anyone have such a queue implemented in C?

+3
source share
2 answers

- (. ) ; - - , ​​ , .

PostQueuedCompletionStatus(), GetQueuedCompletionStatus(), . ..

, , IOCP, , I/O. , ++, , API C .

+5

PostThreadMessage/WaitForSingleObject - win32.

SetEvent() ( ) WaitForSingleObject() ( WaitForMultipleObjects(), ) ( ), , , , , .

:

in producer...
   ...
   create item
   acquire_lock
   push item onto queue
   release_lock
   SetEvent(...)
   ...

in consumer...
   while(true)
      WaitForSingleObject(event)
      acquire_lock
      pop item from queue
      release_lock
      process item
      release item
+1

Source: https://habr.com/ru/post/1730197/


All Articles