使用CreateThread()时,两个线程是否可以使用单个函数“ThreadProc”作为其线程过程?两个线程可以使用相同的线程程序吗?
HANDLE thread1= CreateThread(NULL, //Choose default security
0, //Default stack size
(LPTHREAD_START_ROUTINE)&ThreadProc,
//Routine to execute. I want this routine to be different each time as I want each thread to perform a different functionality.
(LPVOID) &i, //Thread parameter
0, //Immediately run the thread
&dwThreadId //Thread Id
)
HANDLE thread2= CreateThread(NULL, //Choose default security
0, //Default stack size
(LPTHREAD_START_ROUTINE)&ThreadProc,
//Routine to execute. I want this routine to be different each time as I want each thread to perform a different functionality.
(LPVOID) &i, //Thread parameter
0, //Immediately run the thread
&dwThreadId //Thread Id
)
请问上面的代码中创建两个线程每个相同的功能(因为线程程序两个线程的相同。)我是不是做正确吗?
如果可能,那么会有任何同步问题,因为两个线程都使用相同的线程程序。
请帮我这个。我非常困惑,无法通过互联网找到任何东西。
从这里开始:http://en.wikipedia.org/wiki/Thread_(computing) – 2013-05-02 08:26:25
你的第二个线程ID将覆盖第一个。如果你不关心线程ID,只需传递NULL即可。如果你在意,使用'dwThreadId1'和'dwThreadId2'(或者一个数组,当然)。 – MSalters 2013-05-02 11:07:33
+1,谢谢:) – Ayse 2013-05-02 11:20:53