Thread: mutex problem

  1. #16
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by grumpy View Post
    For example, if that startup code creates a file that is needed in the main thread, the main thread needs to grab the mutex, check if the file exists, and - if it doesn't - release the mutex and try again (preferably with a small Sleep() to stop thrashing the CPU).
    Main thread could just create Event
    and start waiting on this event

    when child thread does its work it sets the event
    and main thread exits the wait and starts reading file or something. no need in polling in this case

    in the OP code main thread could start waiting on the mutex which is not created yet
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by vart View Post
    Main thread could just create Event
    and start waiting on this event

    when child thread does its work it sets the event
    and main thread exits the wait and starts reading file or something. no need in polling in this case

    in the OP code main thread could start waiting on the mutex which is not created yet
    Yeah, indeed. There are all sorts of ways.

    The basic concern, however, is that radeberger is relying on one thread completing some action before another thread grabs the mutex. But doing nothing that ensures that sequence of events actually occurs. These things don't happen by magic.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM