Originally posted by weaknessforcats
Help with Semaphores/Locks
Collapse
X
-
No I am trying to manage threads. Would it help to see the semaphore code that was given to us? -
Are you trying to use this semaphore within a single process ??
If so, then where are your critical sections ??Leave a comment:
-
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?Tags: None
Leave a comment: