Author Topic: Semaphores using pthreads  (Read 7174 times)

0 Members and 3 Guests are viewing this topic.

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Semaphores using pthreads
« on: March 04, 2009, 11:48:14 pm »
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?   

Offline nslay

  • Hero Member
  • *****
  • Posts: 786
  • Giraffe meat, mmm
    • View Profile
Re: Semaphores using pthreads
« Reply #1 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.
An adorable giant isopod!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Semaphores using pthreads
« Reply #2 on: March 05, 2009, 10:13:03 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).
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Semaphores using pthreads
« Reply #3 on: March 05, 2009, 10:53:26 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.

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Re: Semaphores using pthreads
« Reply #4 on: March 05, 2009, 11:18:34 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.