In the following program, I created the thread pthread_t thread1, which crashed in the func() function. I am interested in what exactly happened for the pthread_join command in main() .
I ran below the program and exited normally, typing "complete". I do not know why?
#include <iostream> #include <string> #include <vector> #include <map> #include <cstring> #include <climits> #include <cstdio> #include<pthread.h> #include <stdlib.h> using namespace std; void* func(void *data) { cout<<"Calling func"<<(long)(data)<<endl; int *a; cout<<a[2]<<endl; pthread_exit(0); } int main( ) { pthread_t thread1; pthread_create(&thread1, 0 , &func, (void*)2); pthread_join(thread1, NULL); cout<<"complete"<<endl; }
c ++ multithreading pthreads
Emptydata
source share