Skip to content

Instantly share code, notes, and snippets.

@skalnik
Created March 12, 2012 01:23
Show Gist options
  • Save skalnik/2019151 to your computer and use it in GitHub Desktop.
Save skalnik/2019151 to your computer and use it in GitHub Desktop.
Buzz Lock
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);
}
...
}
@skalnik
Copy link
Author

skalnik commented Mar 12, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment