mutex problem

This is a discussion on mutex problem within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by grumpy For example, if that startup code creates a file that is needed in the main thread, ...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,207
    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%.

Page 2 of 2 FirstFirst 12
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, 10: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, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21