synch - /* * Header file for synchronization primitives. */...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * Header file for synchronization primitives. */ #ifndef _SYNCH_H_ #define _SYNCH_H_ /* * Dijkstra-style semaphore. * Operations: * P (proberen): decrement count. If the count is 0, block until * the count is 1 again before decrementing. * V (verhogen): increment count. * * Both operations are atomic. * * The name field is for easier debugging. A copy of the name is made * internally. */ struct semaphore { char *name; volatile int count; }; struct semaphore *sem_create(const char *name, int initial_count); void P(struct semaphore *); void V(struct semaphore *); void sem_destroy(struct semaphore *); /* * Simple lock for mutual exclusion. * Operations: * lock_acquire - Get the lock. Only one thread can hold the lock at the * same time. * lock_release - Free the lock. Only the thread holding the lock may do * this. * lock_do_i_hold - Return true if the current thread holds the lock; * false otherwise. * * These operations must be atomic. You get to write them.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

synch - /* * Header file for synchronization primitives. */...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online