Ok so I need to pick some brains.
Basically, I have a programming assignment to implement semaphores using pthread condition variables and a spin lock. Now the problem I have run into is that in order to block/signal threads my professor is looking for us to use pthread_cond_wait/timedwait and pthread_cond_broadcast/signal. But pthread_cond_wait requires the locking mutex as its second argument, and well we aren't allowed to use pthread_mutexs because we are using a spin lock. How would you fine gentle man suggest i work around it?
Why in the world are you using a spin lock here? I sure hope lock contention is low or the critical section is trivial.
Quote from: nslay on March 05, 2009, 10:04:41 AM
Why in the world are you using a spin lock here? I sure hope lock contention is low or the critical section is trivial.
I would guess it's for school. (I had much worse assignments in my operating systems class).
Quote from: MyndFyre on March 05, 2009, 10:13:03 AM
Quote from: nslay on March 05, 2009, 10:04:41 AM
Why in the world are you using a spin lock here? I sure hope lock contention is low or the critical section is trivial.
I would guess it's for school. (I had much worse assignments in my operating systems class).
Yeah, same. It's to learn how the stuff works, not how to use things properly. It's the same as the old "implement a bubble sort" thing.
Quote from: iago on March 05, 2009, 10:53:26 AM
Quote from: MyndFyre on March 05, 2009, 10:13:03 AM
Quote from: nslay on March 05, 2009, 10:04:41 AM
Why in the world are you using a spin lock here? I sure hope lock contention is low or the critical section is trivial.
I would guess it's for school. (I had much worse assignments in my operating systems class).
Yeah, same. It's to learn how the stuff works, not how to use things properly. It's the same as the old "implement a bubble sort" thing.
It's more like laugh at the 95% of the class that doesn't have a clue as to how to implement an atomic lock, but what I am doing here is the extra credit part of the assignment, and I was right it's not entirely possible to do it like he stated without having mutexs instead of the lock, so know I get to implement the whole thread blocking/queueing/signaling by hand.