Please help with multi-threading concept.

hi all, i got a few questions regarding implementing multi-threading with in Visual C++ with MFC.

Say, i have a main process called theApp (derived from CWinApp).... if i have create a new thread, say thread1 (derived from CWinThread), in theApp, can i still create another thread, say thread1_1 (derived from CWinThread) IN thread1 ??

In other words, does multi-threading mean

i) having multiple threads ONLY in the main process, theApp (from CWinApp) ???

OR

ii) having multiple threads anywhere, even in another sub-thread (threads in threads) ???

thanks a lot

Comments

  • [blue]you can create threads anywhere at any time. But I'd use CreateThread() for worker threads.

    Another thing to watch out for -- you can't update a dialog box in the main thread with information from another thread. Call PostThreadMessage() to let thread #2 send data to the main thread so that the main thread can update the dialog box.[/blue]

    : hi all, i got a few questions regarding implementing multi-threading with in Visual C++ with MFC.
    :
    : Say, i have a main process called theApp (derived from CWinApp).... if i have create a new thread, say thread1 (derived from CWinThread), in theApp, can i still create another thread, say thread1_1 (derived from CWinThread) IN thread1 ??
    :
    : In other words, does multi-threading mean
    :
    : i) having multiple threads ONLY in the main process, theApp (from CWinApp) ???
    :
    : OR
    :
    : ii) having multiple threads anywhere, even in another sub-thread (threads in threads) ???
    :
    : thanks a lot
    :

  • : [blue]you can create threads anywhere at any time. But I'd use CreateThread() for worker threads.
    :
    : Another thing to watch out for -- you can't update a dialog box in the main thread with information from another thread. Call PostThreadMessage() to let thread #2 send data to the main thread so that the main thread can update the dialog box.[/blue]
    :

    Thats not totally true Stober, I can update any dialog control in the main thread without PostThreadMessage() by the use of either some global CWnd, passing the main thread's 'this' member to the thread to use, or by using AfxGetMainWnd() to get the CWnd I need. I'm sure there are other ways.


    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • :
    : Thats not totally true Stober, I can update any dialog control in the main thread without PostThreadMessage() by the use of either some global CWnd, passing the main thread's 'this' member to the thread to use, or by using AfxGetMainWnd() to get the CWnd I need. I'm sure there are other ways.
    :

    I tried something like that once and my program crashed. Microsoft docs say you can't do it.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories