Threading Question.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Threading Question.

  1. #1
    Join Date
    Oct 2009
    Posts
    4

    Threading Question.

    Hello, I am fairly new to the concept of threading in C++ but I am giving it a go and trying to create a thread class. Creating a thread is easy enough with _beginthreadex. But I have hit a wall. So far my class is quite simple it. The constructor takes a "this" pointer ans uses it to pass to the thread routine which casts it back to the correct class type and executes a long running method while a progress bar informs the user. All very simple. I am using RegisterWaitForSingleObject to initiate a callback routine that stops the progress bar after the thread has finished it's job. Here is the problem. Where do I call UnregisterWait? The main thread has moved on and there's no way for it to know when the worker thread has finished, and i'm not allowed (according to MSDN) to call UnregisterWait from inside the CallBack Routine. So where is it supposed to be called? The Callback routine is the only method that knows when the thread has completed it's work. Help! :-)

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    Re: Threading Question.

    Maybe a solution might be to send a custom WM_APP message to your main window. Then when the main window receives this WM_APP message, it can call the UnregisterWait.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,990

    Re: Threading Question.

    concept of threading in C++
    Sorry but there's no such a concept. C++ is indifferent to threading of any nature.
    Best regards,
    Igor

  4. #4
    Join Date
    Apr 2010
    Posts
    1

    Re: Threading Question.

    You wrote: ... The main thread has moved on and there's no way for it to know when the worker thread has finished...

    - you can WaitForSingleObject(<worker theread>) in the main thread to get the worker theread's state.

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Threading Question.

    Let me answer with a different question: What is the need of calling 'RegisterWaitFor SingleObject()' in the first place?
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center