Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help Needed : Race condition while removing semaphore(sysvsem semaphore)

Reply
Thread Tools

Help Needed : Race condition while removing semaphore(sysvsem semaphore)

 
 
techi_C
Guest
Posts: n/a
 
      08-10-2006
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

 
Reply With Quote
 
 
 
 
zhao.kaiyong@gmail.com
Guest
Posts: n/a
 
      08-10-2006

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.

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      08-10-2006
"techi_C" <(E-Mail Removed)> wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with while condition OR condition Bill W. Ruby 13 05-09-2011 09:42 PM
Example code from SwingWorker documentation could have race condition? lionelv@gmail.com Java 3 02-04-2007 07:27 AM
Can static member cause a race condition? alexvodovoz@gmail.com ASP .Net 1 08-07-2006 12:17 PM
Mega Pixel race is like the Mhz Race Hugo Drax Digital Photography 7 01-12-2004 11:07 AM
race condition question jimjim Java 6 11-02-2003 07:55 PM



Advertisments