Stopping/starting threads

This is a discussion on Stopping/starting threads within the Windows Programming forums, part of the Platform Specific Boards category; I use a boolean var to check if a thread should stop. Code: while(bRun){ //Do something Sleep(lInterval); } Is this ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Stopping/starting threads

    I use a boolean var to check if a thread should stop.
    Code:
    while(bRun){
      //Do something
      Sleep(lInterval);
    }
    Is this the only way to do it? I tried to search for the topic, but found nothing helpful..

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    No, this isn't the only way. Try looking up CreateEvent, SetEvent, ResetEvent, and WaitForSingleObject on MSDN.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I am aware of the createevent, etc..
    I just don't think this is the way for me..
    The thread has to run continuously, only stopped when certain windows are opened.
    When using CreateEvent(), you wait for the event to be set/reset.?

  4. #4
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I have never used CreateEvent - I just know that it is another option. I really see nothing wrong with the method you are already using. What exactly is the problem, or are you just wondering if there is a better alternative?

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Just wondering..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  2. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  3. Classes and Threads
    By Halloko in forum Windows Programming
    Replies: 9
    Last Post: 10-23-2005, 05:27 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