Thread: Question about creating threads

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Question about creating threads

    I was a little confused after reading the stuff on MSDN about CreateThread, ThreadProc etc.

    1. When I create a thread, does it keep running over and over until ExitThread is called, or does returning any value kill it? The only one I've seen in action used a while(1) infinite loop and apparently returned when done or on error.

    2. After calling CreateThread, can you call the ThreadProc(&lpParameter) to send it commands etc, just as if you were calling SendMessage on a callback for a window? I kind of wondered why that's a single pointer instead of allowing you to declare the ThreadProc with whatever vars you want it to receive (like window callbacks get HWND, MSG, LPARAM, WPARAM).

    Basically, what I'd like to do is create a client thread for a winsock app to connect, if necessary reconnect, and handle sending/receiving socket data. It's a single connection that should stay open as long as the app is running, but if the other side is disconnected for some reason it needs to keep trying to reconnect. The reason for keeping it a separate thread is mainly that some of the data being transferred can take a long time. I suppose it's similar to writing an FTP app, but this is always connecting to the same place, automatically.
    Last edited by Viper187; 07-25-2009 at 02:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating handheld video games(odd question)
    By nubby in forum Tech Board
    Replies: 0
    Last Post: 03-11-2008, 04:18 PM
  2. simple question on creating a window
    By black in forum Windows Programming
    Replies: 5
    Last Post: 12-29-2005, 12:10 PM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 02:39 PM
  5. Threads terminate when parent process does?
    By BigDaddyDrew in forum Windows Programming
    Replies: 1
    Last Post: 04-21-2004, 04:32 PM