当使用 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
)
上面的代码会创建两个线程,每个线程都具有相同的功能(因为两个线程的线程过程是相同的。)我做对了吗?
如果有可能,那么会有任何同步问题,因为两个线程都使用相同的线程过程。
请帮我解决一下这个。我真的很困惑,在互联网上找不到任何东西。