Thread: synchronization problem

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Question synchronization problem

    Hi,

    I have 1 master thread and 4 worker threads. I want to be able to have the master thread call cond_broadcast() only when all of the worker threads are in cond_wait()...

    If I increment a certain counter before calling cond_wait then I have this scenario for you.. what if the last thread increments the counter and then the master thread exits out of its loop and calls cond_broadcast while the last thread has not called cond_wait() yet.

    you see, my problem is hard and I am stumped.

    I would greatly appreciate any help. Thank you.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    So increment the counter at the end of the cond_wait function.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2
    how would you increment at the end?

    if it calls cond_wait first and the counter incrementing is after cond_wait then it will never get incremented.

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. time synchronization problem
    By freeindy in forum C Programming
    Replies: 1
    Last Post: 04-19-2007, 06:25 AM