Es ist mein erstes Mal zu debuggen C++ Multi-Thread-Programm unter Eclipse und kann den folgenden Fehler nicht lösen.C++ Eclipse Multithread-Fehler
#include <iostream>
#include <pthread.h>
using namespace std;
#define NUM_THREADS 5
void* say_hello(void* args)
{
cout << "Hello World" << endl;
}
int main()
{
pthread_t tids[NUM_THREADS];
for(int i = 0; i < NUM_THREADS; ++i)
{
int ret = pthread_create(&tids[i], NULL, say_hello, NULL);
if (ret != 0)
{
cout << "pthread_create error: error_code=" << ret << endl;
}
}
pthread_exit(NULL);
}
Das Konsolenprotokoll ist:
21:50:36 **** Incremental Build of configuration Debug for project thread1 ****
> make all Building file: ../src/thread1.cpp Invoking: GCC C++ Compiler
> g++ -Ipthread -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP
> -MF"src/thread1.d" -MT"src/thread1.d" -o "src/thread1.o" "../src/thread1.cpp" ../src/thread1.cpp: In function ‘void*
> say_hello(void*)’: ../src/thread1.cpp:10:1: warning: no return
> statement in function returning non-void [-Wreturn-type] }^
> Finished building: ../src/thread1.cpp Building target: thread1
> Invoking: GCC C++ Linker g++ -o "thread1" ./src/thread1.o
> -lpthread Finished building target: thread1
>
> 21:50:37 Build Finished (took 545ms)
Kann jemand zeigen, wo mein Fehler ist? Danke für Ihre Hilfe.
Sie erklären 'say_hello' etwas (vom Typ' void * ') zurückzukehren, aber Sie tatsächlich nichts zurück. –
Ich sehe keinen Fehler, aber die Warnung ist ziemlich klar, nicht wahr? – user463035818
Müssen Sie 'Pthread' verwenden? Wenn Sie C++ 11 oder neuer verwenden, können Sie 'std :: thread' verwenden, das tatsächlich mit dem Typsystem funktioniert, und IMHO ist einfacher zu verwenden. – NathanOliver