philosophers_prep/1_thread_basics.txt

20 lines
854 B
Plaintext

Assignment name: thread_basics
Expected files: thread_basics.c
Allowed functions: memset, printf, malloc, free, write, pthread_create,
pthread_detach, pthread_join, usleep, gettimeofday
-------------------------------------------------------------------------------
Create a program that launches 2 threads. Each thread should print its ID and a different message.
The main program must wait for both threads to finish before exiting.
Thread 1 should print: "Thread 1: Hello from thread 1"
Thread 2 should print: "Thread 2: Hello from thread 2"
The program must accept as an argument the number of messages each thread should print.
Usage: `./thread_basics 5`
Hint: This exercise teaches you the basics of pthread_create and pthread_join.
Remember to check the return values of pthread functions.
Use a structure to pass arguments to threads.