473,769 Members | 5,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Needed : Race condition while removing semaphore(sysvs em semaphore)

Hi
I'm getting a problem while removing semaphore from system.

Before removing semaphore I'm checking the usage count of a smaphore.

// checking usage count
usage_count = semctl(sem_ptr->semid, 1, GETVAL, NULL);
if( usage_count 1 )
// return don't remove semaphore
else
// remove semaphore

If usage count is more than 1 then I'm not removing it.It means that at
this time there are more than one threads waiting for resource.

The problem is coming when after checking the usage_count = 1 if
usage_count becomes 2.
then problem is coming.This operation is not atomic.the usage_count
should not be 2 while removing semaphore.

Please anybody can tell me that How to avoid this problem.

Regards,
Pawan

Aug 10 '06 #1
2 2146

techi_C wrote:
Hi
I'm getting a problem while removing semaphore from system.

Before removing semaphore I'm checking the usage count of a smaphore.

// checking usage count
usage_count = semctl(sem_ptr->semid, 1, GETVAL, NULL);
if( usage_count 1 )
// return don't remove semaphore
else
// remove semaphore

If usage count is more than 1 then I'm not removing it.It means that at
this time there are more than one threads waiting for resource.

The problem is coming when after checking the usage_count = 1 if
usage_count becomes 2.
then problem is coming.This operation is not atomic.the usage_count
should not be 2 while removing semaphore.

Please anybody can tell me that How to avoid this problem.

Regards,
Pawan
Can you tell me how do you use the semphore and the threads. I think
it's the problem about the thread.

Aug 10 '06 #2
"techi_C" <Pa************ *@gmail.comwrot e:
I'm getting a problem while removing semaphore from system.
Please anybody can tell me that How to avoid this problem.
Yes. Anybody in a newsgroup where semaphores are on topic can. They're
not ISO C, so they're off topic here.

Richard
Aug 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4358
by: Bastian Hammer | last post by:
Hi I´m wondering why there are so few examples with Semaphore. Is it obsolete? I´ve got a Class Data. It offers 2 Threads methods for updating, editing, .. a private dictionary. Now I have to make sure, that both threads are synchronal,
4
1980
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 place (buffer) with "n" capacity. The user provides these parameters on startup. The buffer works with a circular queue. It's a console application. My implementation is working with Semaphores to synchornize everything. I think it's synchornized...
5
4607
by: marvind | last post by:
I tried using a Semaphore class (have included the full listing reproduced from article Figure 1 at the end of this email) in .NET 1.1. It works fine most of the time, however, I see the following error occassionally: 08/28/2005 17:32:42.82, Verbose, QueryObject.MergeSubQuery, Exception: Too many posts were made to a semaphore in mscorlib. Server stack trace:
5
2523
by: Unni | last post by:
Hello all, I m facing a memory related problem with semaphores. Our business application uses semaphores extensively and the limit imposed by the OS on the number of semaphores that can exist on the system is only 128. This could be increased to a higher value but that would not be a permanant solution to my belief. We are using the sem_get, sem_acquire php functions. After the use we are releasing the semaphore by using sem_release.
3
5078
by: bangaw | last post by:
i'm currently using c++ on windowsXP, unistd.h doesnt work for windows what other substitute for it could i use to replace it Pls. Help me Pls pls the code goes as follows #include <stdio.h> #include <unistd.h> #include <pthread.h>
1
2272
by: cranfic | last post by:
Please help... To make it simple, I have a simple test C program which calls my semphore library functions only. (It doesn't call any db2 function at all). And the following is the test program: #include "hasem.h" #include <semaphore.h> #include <stdio.h>
0
2251
by: Samuel R. Neff | last post by:
I'm having trouble creating a Semaphore with read-access rights for everyone. Originally I was trying to use this code: semaphore = new Semaphore(maxLocks, maxLocks, "RwLock#" + name); but when using that code to create a Semaphore instance for an existing system semaphore (i.e., the second time the code gets hit), I get an UnauthorizedAccessException. So I tried specifying that everyone has read rights:
0
2215
by: Dmitriy V'jukov | last post by:
I want to announce release 1.1 of Relacy Race Detector. First of all, now you can freely DOWNLOAD latest version of Relacy Race Detector DIRECTLY FROM WEB: http://groups.google.com/group/relacy/files Main change in release 1.1 is support for standard synchronization primitives: 1. mutex (std::mutex, pthread_mutex_init, InitializeCriticalSection) 2. rw_mutex (pthread_rwlock_init, InitializeSRWLock)
1
2131
by: Ajb181 | last post by:
hi all. i have a template class that i can not link. there is no problem when i add the method def's inside the header file but as soon as i move them out i get a link error where i define the object. i have tryed a simple test of the same code and it links fine so am baffeled at what is happing this is my simple test that complies and links bool test(); template <class T> class queue
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.