|
-
Jul 30th, 2001, 03:21 AM
#1
Thread Starter
Member
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 ?
-
Aug 28th, 2001, 06:25 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|