Thread: Multithreading and Function Calls

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    67

    Multithreading and Function Calls

    I'm working on a chat client. Basically, I want to convert what I have now to a multi-threaded version. I'm having a hard time understanding the concept, however.

    ParseData(SOCKET, char *);
    ConnectThread(LPVOID);
    RecvThread(LPVOID);

    I'm not even sure how to word my question...

    Now, say I have 8 RecvThreads running, and each one calls ParseData at approximately the same time. Will ParseData run one at a time, 8 times. Or will they all be running concurrently like the threads?

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Depending on your CPU(Eg. whether or not it is multi-core or not), there is no 'real' execution of two programs at the same time(If we look past features such as HT and so on).

    However, threads run independently of each other. This means that there would be 8 instances of ParseData running. This, however, introduces another problem for you to deal with and understand; synchronization. If you have, for example, a character array allocated on the stack in main, and pass it as a pointer to the threads, and they will try to parse/modify it at the same time, they will succeed, with ill-defined results. One thread might be parsing data that's already been parsed by another thread.

    Consider looking into Critical Sections, mutexes and events.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    67
    That's what I was wondering. Since ParseData isn't a thread, I wasn't sure if it was going to bottleneck at those function calls. And I don't have any trouble with syncronization so far. Each thread has its own data to modify.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multithreading in c
    By thebrighter in forum C Programming
    Replies: 8
    Last Post: 07-10-2007, 01:17 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Multithreading with the Windows API
    By Xzyx987X in forum Windows Programming
    Replies: 7
    Last Post: 11-07-2003, 12:22 AM
  4. function pointer & Thread Parameter :: Multithreading
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 09-11-2002, 08:42 AM
  5. _beginthread when function has more than one parameter
    By blundstrom in forum C Programming
    Replies: 5
    Last Post: 10-04-2001, 12:28 PM