Thread: How to resume thread at the specific time instance?

  1. #1
    Registered User
    Join Date
    Dec 2006

    Smile How to resume thread at the specific time instance?

    Dear all,

    I met one problem about resuming the thread. The thread function init() should be executed when the thread test_thread() is resumed. However, it is never done by my following snippet of code as follows. I don't know where the problem is. Can you help me a little?

    Thanks in advance,



    // Include relevant libs.
    #include "windows.h"
    //global vars.
    HANDLE Handle_1 = 0;
    DWORD WINAPI init()
    void test_thread(void)
    	DWORD dwThreadId;
    	Handle_1 = CreateThread( NULL, 0, init, NULL, CREATE_SUSPENDED, &dwThreadId );
    int main() 
         ResumeThread( Handle_1 );

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Your code looks roughly correct, although there are a couple of issues that may or may not be present in your actual code.
    1. The required signature for a thread function is: DWORD WINAPI ThreadProc(LPVOID lpParameter);
    2. If there is nothing stopping it, the main function may finish and exit the process before the second thread gets a chance to run. You could stop this by waiting until the second thread has finished before exiting main. You can do this using WaitForSingleObject(Handle_1).

    If neither of these solves the problem, maybe you could post a minimal compilable example that demonstrates the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  2. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  3. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  4. Multi-Thread Programming
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2002, 02:53 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM