#include <thread>
void foo()
{
// do stuff...
}
int main()
{
std::thread first (foo);
first.join();
}
sequence of instructions that can be executed concurrently
void task1(std::string msg)
{
std::cout << "task1 says: " << msg;
}
std::thread t1(task1, "Hello");
t1.join();
thread thread1(threadFunction);
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <iostream>
void *task(void *argument){
char* msg;
msg = (char*)argument;
std::cout << msg << std::endl;
}
int main(){
pthread_t thread1, thread2;
int i1, i2;
i1 = pthread_create(&thread1, NULL, task, (void*) "thread 1");
i2 = pthread_create(&thread2, NULL, task, (void*) "thread 2");
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
return 0;
}
#include<thread>
std::thread thread_object(callable)
Code Example |
---|
Cpp :: palindrome program in c++ |
Cpp :: c++ remove element from vector |
Cpp :: c++ initialize vector of vector with size |
Cpp :: 58. Length of Last Word leetcode solution in c++ |
Cpp :: cout c++ |
Cpp :: stoi function in c++ library |
Cpp :: vector find |
Cpp :: inline function in c++ |
Cpp :: See Compilation Time in c++ Program |
Cpp :: c++ hashmaps |
Cpp :: input cpp |
Cpp :: Setting a number of decimals on a float on C++ |
Cpp :: c++ int length |
Cpp :: how to split string into words c++ |
Cpp :: c include |
Cpp :: new line in c++ |
Cpp :: c++ operator overloading |
Cpp :: c++ in cmd |
Cpp :: constructor in cpp |
Cpp :: inline c++ |
Cpp :: convert char to int c++ |
Cpp :: c++ get last element in vector |
Cpp :: count sort algorithm |
Cpp :: cpp linked list |
Cpp :: c++ find index of all occurrences in string |
Cpp :: how creat matrix column in c++ |
Cpp :: Integer Moves codeforces solution |
Cpp :: cmake g++ address sanitizer |
Cpp :: creating node in c++ |
Cpp :: recursive factorial of a number |