Results 1 to 2 of 2

Thread: Multithreading

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    50

    Multithreading

    I have one simple question about multithreading. I do a program which will start about 30 threads at the same time. Although I can write special function for each threads, I am interested if to write the only one thread function is possible (I know - it IS possible, but I want the "errorless" and "bluescreenless" code... Then I start 30 threads (I use MFC, so AfxBeginThread will be called) and all threads will have the same function. Each thread will use another data, of course. Is this possible ?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It is possible. You simply create one Parameter Structure for each thread (or an array of those structures, so you can create threads in a loop) and then call AfxBeginThread once for each thread with the same function but different parameters.
    Code:
    struct PARAMS
    {
    int a;
    int b;
    }
    
    UINT ThreadFunc(LPVOID pData);
    
    .
    .
    .
    PARAMS params[30];
    for(...          // fill all the fields
    
    for(i=0;i<30;i++)
    AfcBeginThread(ThreadFunc, params[i];
    That'll do it

    All the buzzt
    CornedBee

Posting Permissions

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



Click Here to Expand Forum to Full Width