Re: Critical section ?

From: Paul F. Johnson (paul_at_all-the-johnsons.co.uk)
Date: 12/21/04


Date: Mon, 20 Dec 2004 23:50:31 GMT

Hi

James wrote:

> How can IncrementIndex be written so that it is thread safe and won't
> deadlock?

A deadlock is caused by thread A waiting for thread B to do something
and at the same time, thread B waiting for thread A to do something -
they both sit there until the user says blow this for a game and crashes
  out.

A couple of ways to get around it - though neither are that good. The
first is to send one thread to sleep on return, so if A should return
first and B arrives first, send B to sleep and have something in A to
wake B up on A's termination. There is another way, but I've had too
much of the Christmas spirit to remember!

Threads can be very powerful, but very tricky.

TTFN

Paul

-- 
http://www.all-the-johnsons.co.uk
Joy!


Relevant Pages

  • Re: Critical section ?
    ... > James wrote: ... >> deadlock? ... thread B waiting for thread A to do something - they ... > first and B arrives first, send B to sleep and have something in A to wake ...
    (alt.comp.lang.learn.c-cpp)
  • Re: multiple threads writing to WebBrowser, getting deadlocked
    ... blocks the messages for the time that you put it to sleep. ... put to sleep, it will seem to simulate a deadlock whereas, it may just ... It was the worker thread which had the call to Sleep in it. ... than just waiting for messages which would get processed eventually) ...
    (microsoft.public.dotnet.languages.csharp)
  • interactivity (measuring + big-picture thoughts)
    ... time it took to do the sleep and the work. ... waiting on the run queue upon awakening should be included. ... why you would want to give them boosts, ... waited-for party -- some conclusions for the design seem to follow. ...
    (Linux-Kernel)
  • Re: My new Beneteau will be here tonight but my wife wants me to wait to open it
    ... I've been waiting 18 months for my new ... I'm honestyly loosing sleep over it. ... > Christmas and they are bring the guitar from Canada (Marc Beneteau just ... > is Jewish, and my wife is Jewish. ...
    (rec.music.makers.guitar.acoustic)
  • Re: Saturday Morning Smoke... 29 April 06
    ... Dog really did me a favor & let me sleep till around ... She's out now, & while waiting for her to yap to come in, it's DGT ...
    (alt.smokers.pipes)