void *func1()
{
int i;
for (i=0;i<10;i++) { printf("Thread 1 is running\n"); sleep(1); }
}
void *func2()
{
int i;
for (i=0;i<10;i++) { printf("Thread 2 is running\n"); sleep(1); }
}
int result, status1, status2;
pthread_t thread1, thread2;
int main()
{
result = pthread_create(&thread1, NULL, func1, NULL);
result = pthread_create(&thread2, NULL, func2, NULL);
pthread_join(thread1, &status1);
pthread_join(thread2, &status2);
printf("\nПотоки завершены с %d и %d", status1, status2);
getchar();
return 0;
}
このコードがあることを、知られていますそれは本の例から取られているからです。だから、Clionは、このエラーを与え、間違いとしてpthread_joinを関数の第二引数をマーク:
error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
私は考え、問題がCmakeListであるthet。ここに私の現在のCMakeListがあります:
cmake_minimum_required(VERSION 3.3)
project(hello_world C CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
set(SOURCE_FILES main.cpp)
add_executable(hello_world ${SOURCE_FILES})
の代わりに、 "それは知られている" の後に "" があります"?" – palladian