Created
March 12, 2012 01:23
-
-
Save skalnik/2019151 to your computer and use it in GitHub Desktop.
Buzz Lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int buzz_lock(buzz_t lock) { | |
... | |
if(full_active_threads(lock)) { | |
add_to_waiting_threads(thread, lock); | |
do { | |
wait(lock); | |
if(is_gold(thread)) { | |
if(is_old(thread, lock)) { | |
add_active(thread, lock); | |
} | |
else if(num_black_waiting(lock) <= 0) { | |
add_active(thread, lock); | |
} | |
} | |
else { | |
if(num_old_gold_waiting(lock) <= 0) { | |
add_active(thread, lock); | |
} | |
} | |
free_threads = lock.max_active_threads - lock.active_threads; | |
} while(free_threads <= 0); | |
} | |
else { | |
add_active(thread, lock); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Intent: Two colors of threads, gold and black. Threads try to acquire lock, and priority is given to old gold threads, then black threads, and lastly gold threads.