Help with Semaphores/Locks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gauchoking11
    New Member
    • Feb 2008
    • 2

    Help with Semaphores/Locks

    To make it clear I am a student with a question and have read the Posting Guidelines, here is what I have written:
    It is contained within a file called synch.cc
    Lock::Lock(char * debugName)
    {
    name = debugName;
    lockHolder = NULL; // no thread yet holds lock
    Semaphore(name, 1);

    }


    Lock::~Lock()
    {
    delete lockHolder;

    }

    void Lock::Acquire()
    {

    IntStatus oldLevel = interrupt->SetLevel(IntOf f);
    semaphore->P();


    (void) interrupt->SetLevel(oldLe vel);
    }

    void Lock::Release()
    {

    IntStatus oldLevel = interrupt->SetLevel(IntOf f);

    ASSERT(isHeldBy CurrentThread() );
    if(isHeldByCurr entThread())
    {
    semaphore->V();
    }
    (void) interrupt->SetLevel(IntOf f);

    }

    bool Lock::isHeldByC urrentThread()
    {
    IntStatus oldLevel = interrupt->SetLevel(IntOf f);
    if(currentThrea d == lockHolder)
    return true;
    (void) interrupt->SetLevel(oldLe vel);

    }

    and I added this to the synch.h under the class lock private section

    Semaphore *semaphore;

    when I run a test on the code it gives me a segmentation error(core dumped) I am stuck and don't know what to do any thoughts?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Are you trying to use this semaphore within a single process ??

    If so, then where are your critical sections ??

    Comment

    • gauchoking11
      New Member
      • Feb 2008
      • 2

      #3
      Originally posted by weaknessforcats
      Are you trying to use this semaphore within a single process ??

      If so, then where are your critical sections ??
      No I am trying to manage threads. Would it help to see the semaphore code that was given to us?

      Comment

      Working...