Created
August 29, 2018 13:50
-
-
Save OctoberWu/2841e11557dce6b56233e1fe1b2e4294 to your computer and use it in GitHub Desktop.
#POSIX #pthread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
// Name : pthread_test.cpp | |
// Author : octoberwu | |
// Version : | |
// Copyright : Your copyright notice | |
// Description : Hello World in C++, Ansi-style | |
//============================================================================ | |
#include <iostream> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
using namespace std; | |
void* threadMission(void *name){ | |
for(int i=0; i<3; ++i){ | |
//sleep(1); | |
printf("threading..."); | |
} | |
} | |
int main() { | |
int ret; | |
pthread_t tid; | |
ret = pthread_create(&tid, NULL, threadMission, NULL); | |
if(ret != 0){ | |
printf("error occuring!"); | |
exit(1); | |
} | |
cout << "Here is main process thread." << endl; | |
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! | |
pthread_join(tid, NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment