multiple threads cpp
#include <iostream>
#include <threads>
#include <vecotr>
std::vector<std::thread*> threads;
for(int i = 0; i < x; i++)
{
threads.push_back(new std::thread(func));
}
multiple threads cpp
#include <iostream>
#include <threads>
#include <vecotr>
std::vector<std::thread*> threads;
for(int i = 0; i < x; i++)
{
threads.push_back(new std::thread(func));
}
c++ multithreading
#include <iostream>
#include <cstdlib>
#include <pthread.h>
using namespace std;
#define NUM_THREADS 5
void *PrintHello(void *threadid) {
long tid;
tid = (long)threadid;
cout << "Hello World! Thread ID, " << tid << endl;
pthread_exit(NULL);
}
int main () {
pthread_t threads[NUM_THREADS];
int rc;
int i;
for( i = 0; i < NUM_THREADS; i++ ) {
cout << "main() : creating thread, " << i << endl;
rc = pthread_create(&threads[i], NULL, PrintHello, (void *)i);
if (rc) {
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us