c 2b 2b multithreading

Solutions on MaxInterview for c 2b 2b multithreading by the best coders in the world

showing results for - "c 2b 2b multithreading"
Kellen
29 Jul 2016
1#include <iostream>
2#include <threads>
3#include <vecotr>
4
5std::vector<std::thread*> threads;
6
7for(int i = 0; i < x; i++)
8{
9  threads.push_back(new std::thread(func));
10}
Barrett
18 Jan 2019
1#include <iostream>
2#include <cstdlib>
3#include <pthread.h>
4
5using namespace std;
6
7#define NUM_THREADS 5
8
9void *PrintHello(void *threadid) {
10   long tid;
11   tid = (long)threadid;
12   cout << "Hello World! Thread ID, " << tid << endl;
13   pthread_exit(NULL);
14}
15
16int main () {
17   pthread_t threads[NUM_THREADS];
18   int rc;
19   int i;
20   
21   for( i = 0; i < NUM_THREADS; i++ ) {
22      cout << "main() : creating thread, " << i << endl;
23      rc = pthread_create(&threads[i], NULL, PrintHello, (void *)i);
24      
25      if (rc) {
26         cout << "Error:unable to create thread," << rc << endl;
27         exit(-1);
28      }
29   }
30   pthread_exit(NULL);
31}