473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(IntOff);
semaphore->P();


(void) interrupt->SetLevel(oldLevel);
}

void Lock::Release()
{

IntStatus oldLevel = interrupt->SetLevel(IntOff);

ASSERT(isHeldByCurrentThread());
if(isHeldByCurrentThread())
{
semaphore->V();
}
(void) interrupt->SetLevel(IntOff);

}

bool Lock::isHeldByCurrentThread()
{
IntStatus oldLevel = interrupt->SetLevel(IntOff);
if(currentThread == lockHolder)
return true;
(void) interrupt->SetLevel(oldLevel);

}

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?
Feb 17 '08 #1
2 1580
weaknessforcats
9,208 Expert Mod 8TB
Are you trying to use this semaphore within a single process ??

If so, then where are your critical sections ??
Feb 17 '08 #2
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?
Feb 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
11
by: FiLH | last post by:
Hello, I would like to know if posix semaphores are inter processes or just semaphores for threads inside the same process. I have not seen it defined in the posix specification I have found,...
4
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage...
4
by: Alex Callea | last post by:
Hi there, We have a web application handling thousands of requests per seconds reading sql server data which is heavily updated. We are generally experiencing no performance problems. On some...
1
by: Edwin New | last post by:
I have a requirement to run two separate postmasters on the one machine. It looks like they compete for resources (semaphores) so won't run concurrently. I compiled twice, specifying different...
8
by: pmm | last post by:
hi all , I am working on a router which is Coded in ansi C ,it uses number of semaphores,threads I want to know that how can we know what threads are currently alive in a program being executed...
1
by: shenanwei | last post by:
I have db2 v8.2.5 on AIX V5.3 with all the switches on Buffer pool (DFT_MON_BUFPOOL) = ON Lock (DFT_MON_LOCK) = ON Sort ...
0
arne
by: arne | last post by:
Hi, I am using Perl ithreads. The threads I create shall access a shared hash. In order to control access to the hash, I would like to use a semaphore. (BTW, does the hash need the protection at...
3
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.