Sleeping threads

This is a discussion on Sleeping threads within the C Programming forums, part of the General Programming Boards category; I tried looking this up but having a hard time cuz all i get are ppl using sleep() is there ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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
    Posts
    6,252
    [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%.

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

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, 04: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

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