#include #include #include // ---------------------------------------------------------- void *PrintHello(void *arg); // ---------------------------------------------------------- int main(int argc, char *argv[]){ pthread_t thread [10]; int i = 0; /*petla startujaca kolejne watki zwieksza numer watka od 0 do 9*/ for(i = 0; i < 10; i++){ int rc = pthread_create(&thread[i], NULL, PrintHello, &i); if (rc){ printf("Return code: %d\n", rc); exit(-1); } /*oczekiwanie watku glownego na nowy watek*/ pthread_join(thread[i], NULL); } printf("End of the main thread!\n"); return 0; } // ---------------------------------------------------------- void *PrintHello(void *arg){ sleep(1); printf("Next boring 'Hello World!' version! (%d)\n", * (int*) arg); return NULL; } DUPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA #include #include #include #define NUM 4 #define LENGTH 100 // ---------------------------------------------------------- typedef struct { long* a; long sum; int veclen; } CommonData; // ---------------------------------------------------------- CommonData data; pthread_t threads[NUM]; pthread_mutex_t mutex; void* calc(void* arg); // Funkcja rozpoczecia // ---------------------------------------------------------- int main (int argc, char *argv[]){ long i, sum = 0; void* status; long* a = (long*) malloc (NUM*LENGTH*sizeof(long)); pthread_attr_t attr; //Prepare data structure for (i=0; i