Results 1 to 4 of 4

Thread: Problem with cross-thread semaphore release [2005]

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    46

    Unhappy 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.

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    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

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  4. #4
    New Member
    Join Date
    Dec 2007
    Posts
    2

    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
  •  



Click Here to Expand Forum to Full Width