First-come-first-served policy for shared resource
===

An exam question:

> A resource is shared between N threads such that access is on a first-com-first-served basis. Explain how you would implement a policy of first-come-first-served.

My answer would be along the lines of (Note: the course is Java based):

> Use a semaphore (binary) to control access to the shared resource. Then create a feeder class/thread to access the semaphore. The feeder thread uses a FIFO queue to implement first-come-first-served. When the semaphore is free it allows the thread a the head of the queue to access the shared resource.

I have just jotted out on paper the above approach and it seems to work.

The question is worth 8 marks in a 20 mark question so I doubt using `new ReentrantLock(true)` would suffice for full marks.

What do you guys think?

Thanks.