Using a condition variable
Shared:
Q = []
cv = Condition()
Producers:
while 1:
job = make_job()
cv.acquire()
Q.append(job)
cv.notify()
cv.release()
Consumers:
while 1:
cv.acquire()
while not Q:
cv.wait()
job = Q.pop()
cv.release()
finish_job(job)
Previous slide
Next slide
Back to first slide
View graphic version