Multithreading in c++

后端 未结 6 2061
轮回少年
轮回少年 2020-12-15 13:48

I want to run one function with different parameters on different threads:

int threads = 3;
int par1[] = {1, 2, 3};
int par2[] = {4, 5, 6};
for (int i=0; i&l         


        
6条回答
  •  甜味超标
    2020-12-15 14:28

    You create a thread in Windows by calling CreateThread. There's an example here.

    Yes, you can dynamically create threads.

    Now, when your "thread function" is getting called (which means the thread started) you use the passed parameter which you've feeded when calling CreateThread.
    At the "thread-function" it's "LPVOID lpParam". You should cast it to your type. If it's two objects you need to pass to the thread then create your own custom struct/class with the appropriate memebers, and pass an instance of it when calling CreateThread so you can use it later. Very straight-forward.

提交回复
热议问题