Skip to content

Instantly share code, notes, and snippets.

@OctoberWu
Created August 29, 2018 13:50
Show Gist options
  • Save OctoberWu/2841e11557dce6b56233e1fe1b2e4294 to your computer and use it in GitHub Desktop.
Save OctoberWu/2841e11557dce6b56233e1fe1b2e4294 to your computer and use it in GitHub Desktop.
#POSIX #pthread
//============================================================================
// 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