-
November 8th, 2011, 04:38 AM
#1
OpenSemaphore Fails occassionally.
Hi forum.
I have the following code inside one function.
Code:
if ((my_os_resource_handle = OpenSemaphore(SEMAPHORE_ALL_ACCESS,FALSE,"Global\\ABC32$SEMAPHORE$%c")) == NULL)
{
error handling
}
This function gets called many times.
For the first time in years, we have seen the problem in a particular system
This call failed three times over a span of two days and to get the program working, the entire system had to be rebooted.
The GetLastError always returned 2
Details of the system.
Windows 2003 Professional
Any thoughts on the same? .... is there any method that I can reproduce the File not available (Error code 2) situation so that I can understand more ....... in other words, are there any techniques to manipulate, access kernel objects ?
-
November 8th, 2011, 06:03 AM
#2
Re: OpenSemaphore Fails occassionally.
Maybe you accidently did something that made the calls to CreateSemaphore, OpenSemaphore & CloseHandle unbalanced? From MSDN http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
The semaphore object is destroyed when its last handle has been closed
-
November 8th, 2011, 11:13 AM
#3
Re: OpenSemaphore Fails occassionally.
Originally Posted by softmessager
For the first time in years, we have seen the problem in a particular system. This call failed three times over a span of two days and to get the program working, the entire system had to be rebooted.
Well, there was a bug or if not a bug, an oversight in your program that finally became exposed.
1) As S_M_A pointed out, is your synchronization done correctly?
2) Do you check for all return values from all Windows API and other library functions?
One reason a lot of programs fail is that false assumptions are made when it comes to calling API functions. The belief is that the function will work, thereby no code is written to check for the return value (or exception if it's a C++ based API). Then that fateful day when these "safe" API function fails, the code reacts by doing nothing and proceeding as if the function didn't fail. Then things fall apart from there.
Regards,
Paul McKenzie
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|