Pergunta de entrevista da empresa Microsoft

Implement a solution for the bounded buffer problem where you have a queue of work items and several producer/consumer threads.

Respostas da entrevista

Sigiloso

20 de out. de 2009

Use a counting semaphore, incrementing each time a producer puts a new item in the queue and decrementing each time a consumer removes an item from the queue.

1

Sigiloso

9 de ago. de 2011

use three binarySemaphore/SemaphoreMutex(both are same) empty full access producer() { wait(empty) wait(access) // Fill the q signal(access) signal(full) } consumer() { wait(full) wait(access) // Consume the q signal(access) signal(empty) } Note : Use signal NOT broadcast when using POSIX cond_wait if you know what i mean.