Thread: Sleeping threads

  1. #1
    Registered User
    Join Date
    Aug 2009

    Sleeping threads

    I tried looking this up but having a hard time cuz all i get are ppl using sleep()

    is there a function that would be able to put a thread to sleep and only get waken up when the main process wants teh thread to do something??? i thought there was sumthing like that when using multithreads like having a thread be in wait mode i guess and waits till the main threads gives it new data to be processed

    im trying to avoid an infinite loop checking a buffer waiting for the main thread to fill up

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    If you are on windows you can use CreateObject(), WaitForSingleObject(), PulseObject() and DeleteObject() to signal between threads.

  3. #3
    Registered User
    Join Date
    Jun 2005
    [Note: this is not a C question].

    Generally, synchronisation between threads and processes would be done using particular types of objects known as critical sections, mutexes, semaphores, or events.

    The techniques to create these objects, and to use them, vary with operating system (as do the type of synchronisation objects supported by different systems). Note that different methods have different trade-offs, so - for each one supported by your compile and operating system - look carefully at what each one does.

    Generally, you are better off avoiding functions concerned with suspending a thread (in effect, telling it to sleep indefinitely) or resuming a thread. Those functions do not, on their own, offer any protection for data that is accessed by multiple threads.
    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.

  4. #4
    Registered User
    Join Date
    May 2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Producer/Consumer - problems creating threads
    By hansel13 in forum C Programming
    Replies: 47
    Last Post: 08-20-2010, 02:02 PM
  2. Need Help: Multi-threading and Synchronization
    By Anom in forum C Programming
    Replies: 7
    Last Post: 12-08-2009, 05:34 PM
  3. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 02:39 PM
  5. Block and wake up certain threads
    By Spark in forum C Programming
    Replies: 9
    Last Post: 06-01-2002, 03:39 AM