News:

How did you even find this place?

Main Menu

Semaphores using pthreads

Started by Nate, March 04, 2009, 11:48:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nate

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?   

nslay

Why in the world are you using a spin lock here?  I sure hope lock contention is low or the critical section is trivial.
An adorable giant isopod!

MyndFyre

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: Joe on January 23, 2011, 11:47:54 PM
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Quote from: Rule on May 26, 2009, 02:02:12 PMOur species really annoys me.

iago

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.

Nate

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.