Skip to content

Instantly share code, notes, and snippets.

@mgiagante
Last active September 27, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgiagante/d0e0585ab9fe0c1b39ac7fc70320abd1 to your computer and use it in GitHub Desktop.
Save mgiagante/d0e0585ab9fe0c1b39ac7fc70320abd1 to your computer and use it in GitHub Desktop.
Semaphores 2
queue resource_queue[5] = [r1, r2, r3, r4, r5]
sem resources = 5
sem queue_mutex = 1
process Consumer {
p(resources)
p(queue_mutex)
resource my_resource = pop(resource_queue)
v(queue_mutex)
delay # Usa el recurso
p(queue_mutex)
push(resource_queue, my_resource)
v(queue_mutex)
v(resources)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment