|
-
Dec 4th, 2007, 05:56 PM
#1
Thread Starter
Member
Problem with cross-thread semaphore release [2005]
Hi all,
I try to use semaphores in .NET.
After using .Waitone in the first thread code, I used .Release in the second thread code in order to resume the suspended first thread. For a couple of times it ran and worked for me, but there is a time when I can't figure out what makes it stop.
The steps as I see them while debugging:
First thread : .Waitone -> I saw it happening.
Second thread : .Release ( First thread suspended )-> I saw it happening;
BUT: The first thread didn't get out of its suspeneded mode.
I can't bring any code here soon, but I'll sure manage with some tips and directions, from anyone of you, which can lead me to a solution for my problem.
-
Dec 4th, 2007, 06:08 PM
#2
Frenzied Member
Re: Problem with cross-thread semaphore release [2005]
Without code, im not sure it is possible to answer your question, but maybe some of the more experienced guys might know.
Cheers
-
Dec 4th, 2007, 06:32 PM
#3
Re: Problem with cross-thread semaphore release [2005]
It sounds like a deadlock, and even WITH code it will be tough to debug. You say that you "saw it happening". How are you doing that?
My usual boring signature: Nothing
 
-
Dec 5th, 2007, 05:05 AM
#4
New Member
Clarification
Greetings.
Allow me to clarify the problem that SuKaSa has graciously posted about in my stead.
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,
Kyre.
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
|