0
0
Operating Systemsknowledge~10 mins

Thread creation and management in Operating Systems - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new thread using the POSIX pthread library.

Operating Systems
pthread_t thread_id;
pthread_create(&thread_id, NULL, [1], NULL);
Drag options to blanks, or click blank then click option'
Apthread_join
Bstart_thread
Cmain
Dpthread_exit
Attempts:
3 left
💡 Hint
Common Mistakes
Using pthread_join or pthread_exit as the thread start function.
Passing main as the thread function.
2fill in blank
medium

Complete the code to wait for a thread to finish execution.

Operating Systems
pthread_t tid;
// thread created earlier
pthread_join([1], NULL);
Drag options to blanks, or click blank then click option'
Athread_id
BNULL
C0
Dtid
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL instead of the thread ID.
Using a variable name not declared as a thread ID.
3fill in blank
hard

Fix the error in the thread function declaration to match pthread requirements.

Operating Systems
void* [1](void* arg) {
    // thread code
    return NULL;
}
Drag options to blanks, or click blank then click option'
Athread_func
Bvoid thread_func
CthreadFunc()
Dint thread_func
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring the function with no parameters or wrong return type.
Using int or void return types instead of void*.
4fill in blank
hard

Fill both blanks to create a thread and wait for it to finish.

Operating Systems
pthread_t tid;
pthread_create(&tid, NULL, [1], NULL);
pthread_[2](tid, NULL);
Drag options to blanks, or click blank then click option'
Athread_func
Bjoin
Cexit
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using pthread_exit instead of pthread_join to wait.
Passing wrong function names.
5fill in blank
hard

Fill all three blanks to create a thread, pass an argument, and wait for it to finish.

Operating Systems
void* [1](void* arg) {
    int* num = (int*)[2];
    printf("Number: %d\n", *num);
    return NULL;
}

pthread_t tid;
int value = 5;
pthread_create(&tid, NULL, [3], &value);
pthread_join(tid, NULL);
Drag options to blanks, or click blank then click option'
Athread_func
Barg
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the argument pointer inside the function.
Passing wrong function names to pthread_create.