我对在 CPU、MFC C++ 上使用多线程感到陌生。我正在尝试初始化两个 CWinThreads 并将它们作为工作线程同时运行,这在我的头文件中
CWinThread *m_thread;
CWinThread *m_thread1;
在我的 cpp 文件中,我试图这样称呼它们
CdecoderD3D9App *decoder_object_1 = new CdecoderD3D9App(460, 1);
m_thread = AfxBeginThread(MainTread, decoder_object_1);
CdecoderD3D9App *decoder_object_2 = new CdecoderD3D9App(460, 2);
m_thread1 = AfxBeginThread(MainTread1, decoder_object_2);
CdecoderD3D9App
是我传递给线程并运行其函数的应用程序类我的线程函数是这样的
UINT Ctesting_projectDlg::MainTread(LPVOID pParam)
{
clock_t t1, t2;
t1 = clock();
CdecoderD3D9App *decoder_object_1 = (CdecoderD3D9App *)pParam;
char *video_source = "my_movie.mp4";
decoder_object_1->InitInstance();
decoder_object_1->run_program(video_source);
t2 = clock();
float diff = (((float)t2 - (float)t1) / 1000000.0F ) * 10;
return 0;
}
UINT Ctesting_projectDlg::MainTread1(LPVOID pParam)
{
clock_t t1, t2;
t1 = clock();
CdecoderD3D9App *decoder_object_3 = (CdecoderD3D9App *)pParam;
char *video_source = "my_movie.m2v";
decoder_object_3->InitInstance();
decoder_object_3->run_program(video_source);
t2 = clock();
float diff = (((float)t2 - (float)t1) / 1000000.0F ) * 10;
return 0;
}
当我调用线程函数时,只有第二个线程正在运行,第一个线程开始运行,但是一旦第二个线程被调用,第一个线程就停止了。无论如何我可以同时运行它们吗?我必须在程序中同时运行四个这样的线程。谢谢你。