#include <iostream>
#include <cstdlib>
#include <pthread.h>
using namespace std;
#define NUM_THREADS 2
int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void *splitLoop(void *threadid)
{
long tid;
tid = (long)threadid;
//cout << "Hello World! Thread ID, " << tid << endl;
int start = (tid * 5);
int end = start + 5;
for(int i = start;i < end;i++){
cout << arr[i] << " ";
}
cout << 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,
splitLoop, (void *)i);
if (rc){
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPHB0aHJlYWQuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIE5VTV9USFJFQURTIDIKCmludCBhcnJbMTBdID0gezAsIDEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDl9OwoKdm9pZCAqc3BsaXRMb29wKHZvaWQgKnRocmVhZGlkKQp7CiAgIGxvbmcgdGlkOwogICB0aWQgPSAobG9uZyl0aHJlYWRpZDsKICAgLy9jb3V0IDw8ICJIZWxsbyBXb3JsZCEgVGhyZWFkIElELCAiIDw8IHRpZCA8PCBlbmRsOwogICBpbnQgc3RhcnQgPSAodGlkICogNSk7CiAgIGludCBlbmQgPSBzdGFydCArIDU7CiAgIGZvcihpbnQgaSA9IHN0YXJ0O2kgPCBlbmQ7aSsrKXsKICAgICAgY291dCA8PCBhcnJbaV0gPDwgIiAiOwogICB9CiAgIGNvdXQgPDwgZW5kbDsKICAgcHRocmVhZF9leGl0KE5VTEwpOwp9CgppbnQgbWFpbiAoKQp7CiAgIHB0aHJlYWRfdCB0aHJlYWRzW05VTV9USFJFQURTXTsKICAgaW50IHJjOwogICBpbnQgaTsK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