Thread: callbacks and threads - technical question

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    36

    callbacks and threads - technical question

    when the system calls a callback function, does it create a separate thread for this?

    i read, for example, that in console programming when i define my own handler(SetConsoleCtrlHandler), system creates separate thread to run this function...

    is it always the case?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Is it always the case? <<

    No. Many callbacks execute on the same thread and are called from within a function you call. For example, when you call EnumWindows(), this function will call your EnumWindowsProc as many times as needed before returning. Therefore, no new thread is needed.

    Another example is the TimerProc callback. This callback is called by DefWindowProc when it receives a WM_TIMER message. Again, the order is, your thread enters DefWindowProc, DefWindowProc calls TimerProc, TimerProc runs and returns and finally DefWindowProc returns. All in the same thread.

    Callbacks that execute in the same thread are more common than callbacks that execute in a new thread. Unfortunately, the documentation is not always as clear as it could be on this matter.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    36
    what about completition routins? or any function that being called upon event triggering?

    do you know another examples (like in console) when new thread is created?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. threads and callbacks
    By steve1_rm in forum C Programming
    Replies: 4
    Last Post: 02-25-2009, 01:34 PM