CreateThread() executes ONLY once ... ?

This is a discussion on CreateThread() executes ONLY once ... ? within the Windows Programming forums, part of the Platform Specific Boards category; Hello. I am working on a multi-threaded application using sockets, and I am using the CreateThread() function. BTW, I am ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Unhappy CreateThread() executes ONLY once ... ?

    Hello. I am working on a multi-threaded application using sockets, and I am using the CreateThread() function. BTW, I am using MS Visual C++ 6.0 Standard on a Windows 98 machine, using MFC for this app. Anyhow, I added a 'AfxMessageBox("Test");' to my thread function, and it is only called once, and then ends the thread. I think it has something to do with WaitFor(Single/Multiple)Object(s), but I tried those. It says the thread's handle needs to have the "SYNCHRONIZE" right, but I don't know how to do that. If you can, please offer any help.

    Thanks,
    Matt U.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I don't use MFC, however, I am awre that MFC has it's own threading and sychronisation classes. Are you using those? If so, I don't know - don't use it! If not, should you be?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Use AfxBeginThread() to create for multithreading in MFC. Otherwise, use __beginthreadex().

    Correct. One solution is an event object.

    HANDLE hEvent = ::CreateEvent(...);

    Kuphryn

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking Thanks ... :)

    Thanks for the help. I will try that in a few minutes.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Anyhow, I added a 'AfxMessageBox("Test");' to my thread function, and it is only called once, and then ends the thread.
    What else would you like it to do? Also, if you created the thread you have the SYNCHRONIZE right. But exactly what are you trying to do?

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,702
    Read this.
    Then come back with specific questions/problems you might have.

    Here is an awsome thread wrapper class you can use too.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 08:52 AM
  2. CreateThread() followed by CloseHandle()?
    By cpjust in forum C++ Programming
    Replies: 5
    Last Post: 03-24-2008, 01:00 PM
  3. compiler doesn't like CreateThread
    By finkus in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2005, 03:06 AM
  4. CreateThread and lpParam
    By Hunter2 in forum Windows Programming
    Replies: 6
    Last Post: 06-02-2004, 05:46 PM
  5. pass several arguments to LPVOID param of CreateThread
    By Echidna in forum Windows Programming
    Replies: 4
    Last Post: 05-05-2002, 11:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21