我正在尝试在 Windows 上使用 pthread win-32,我创建了一个示例应用程序来测试 pthread 库,但程序运行不正常,减去错误代码令人兴奋。我使用 MSVC 进行编译,使用 cmake 构建项目。
我得到的错误:Process finished with exit code -1073741515 (0xC0000135)
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
void *myThreadFun(void *vargp)
{
Sleep(1);
printf("Printing GeeksQuiz from Thread \n");
return NULL;
}
int main()
{
pthread_t thread_id;
printf("Before Thread\n");
pthread_create(&thread_id, NULL, myThreadFun, NULL);
pthread_join(thread_id, NULL);
printf("After Thread\n");
exit(0);
}
制作清单:
cmake_minimum_required(VERSION 3.17)
project(untitled6)
set(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_FLAGS -pthread)
set(THREADS_PREFER_PTHREAD_FLAG ON)
include_directories("C:/Users/Tharindu/Downloads/pthrad/Pre-built.2/include")
add_executable(untitled6 main.cpp)
target_link_libraries(untitled6 C:/Users/Tharindu/Downloads/pthrad/Pre-built.2/lib/pthreadVC2.lib)
C:/Users/Tharindu/Downloads/pthrad/Pre-built.2/include
目录包括pthread.h
,sched.h
和semaphore.h
有人可以帮我解决这个问题吗?
谢谢