MUP1+-+Øvelse+3.2.1


 * Øvelse 3.2.1**

Vigtigt i forhold til compile er -lpthread: g++ -o threads3.2.1.cpp -lpthread

__**Kode dumps fra øvelse:**__

//void *thread_function(void *arg)// //{// //char* message;// //message = (char*) arg;// //for( int i=0; i<9; i++ )// //{// //cout << "Hello #" << i+1 << " from thread " << message << endl;// //sleep(1);// //}// //cout << "Thread " << message << " terminates" << endl;// //pthread_exit(0);// //}//
 * Thread funktionen:** __hvad der skal ske når hver threat kører__

//res1 = pthread_create(&a_thread, NULL, thread_function, (void*) message1);// / //res2 = pthread_create(&b_thread, NULL, thread_function, (void*) message2);// __bruges til at checke om tråden er oprettet korrekt.__
 * Int main:**

//pthread_join(a_thread, NULL);// / //pthread_join(b_thread, NULL);// __starter trådene__

//int main// //{// //int res1, res2;// //pthread_t a_thread;// //pthread_t b_thread;// //char* message1 = "1";// //char* message2 = "2";//

//cout << "Main: Creating threads" << endl;// //res1 = pthread_create(&a_thread, NULL, thread_function, (void*) message1);// //res2 = pthread_create(&b_thread, NULL, thread_function, (void*) message2);// //cout << "Waiting for threads to finish" << endl;//

//if( res1 != 0 )// //{// //perror("Tread creation failed");// //exit( 1 );// //}//

//if( res2 != 0 )// //{// //perror("Tread creation failed");// //exit( 1 );// //}//

//pthread_join(a_thread, NULL);// //pthread_join(b_thread, NULL);//

//cout << "Main: Exiting" << endl;// //}//