By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,750 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,750 IT Pros & Developers. It's quick & easy.

Problem with cross-thread semaphore release [.NET 2005]

P: 1

After first noticing a malfunction in my application, I ran some tests which have given me the following insights on the code performance:

-The " infinite" loop which waits on the semaphore first thing in every iteration, may succeed in going through several iterations.
-The number of successful iterations may differ with every execution, as well as with timing differences caused by the different placement of breakpoints.
-In every case, the semaphore release fails rather early on (the number of successful iterations never rises above 10).
-The problem seems to be with the Semaphore.Release() method invocation.

The last insight is clear to me from seeing the following:
The loop ran once, then started again, invoked the Semaphore.WaitOne() method and entered suspension.
A breakpoint was then reached on the Semaphore.Release() invocation line.
Upon reaching this breakpoint, I looked at the state of the main thread in question (the one with the loop), and saw it was suspended on the WaitOne() line.
I put a breakpoint on the first line after the WaitOne invocation, stepped over the Release line and let the program run.
The new breakpoint was never reached.
I then paused the program and saw that the aforementioned thread was still in the exact same state (I put a counter in the loop, so I can tell it was not executed without my knowing).

That`s about the summary of things as I know them to be.
I would much appreciate any pointers as to what could cause a Release() invocation to *not* release a waiting thread.

Thanks in advance.
Dec 6 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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