POSIX Threads, Conditions, Semaphores

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:32 AM on 11/25/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

38 Terms

1
New cards

What does the POSIX threads API add to Unix?

Threading capabilities.

2
New cards

What are POSIX threads commonly referred to as?

Pthreads.

3
New cards

What is the basic unit of concurrency in POSIX threads?

Thread.

4
New cards

What function is used to create a thread in Pthreads?

pthread_create().

5
New cards

What does the pthread_create() function require as an argument?

Start function and argument.

6
New cards

What is the type used for declaring a thread in Pthreads?

pthread_t.

7
New cards

What kind of object is the thread attribute in pthread_create()?

pthread_attr_t.

8
New cards

What are the possible ways that POSIX threads can terminate?

Exiting the application, calling pthread_exit(), or returning from the start function.

9
New cards

What is the purpose of pthread_join()?

To wait for a thread to finish and to retrieve its exit status.

10
New cards

What is a mutex used for in POSIX threads?

To ensure mutual exclusion when accessing shared data.

11
New cards

How can a mutex be initialized in POSIX threads?

Using PTHREAD_MUTEX_INITIALIZER or pthread_mutex_init().

12
New cards

What is a function that will try to lock a mutex?

pthread_mutex_trylock().

13
New cards

What happens when you destroy a mutex that is currently locked?

It results in an error.

14
New cards

What is the behavior of the default mutex regarding recursive locks?

It may not allow recursive locks.

15
New cards

What type of variable works with mutexes for signaling between threads?

Condition variables.

16
New cards

What is the function used to wait on a condition variable?

pthread_cond_wait().

17
New cards

What method is used to signal a single waiting thread?

pthread_cond_signal().

18
New cards

What happens if you signal a condition variable with no waiting threads?

Nothing occurs.

19
New cards

What is the purpose of POSIX semaphores?

To control access to shared resources between processes or threads.

20
New cards

How do you initialize a POSIX semaphore?

By using sem_init().

21
New cards

What operation corresponds to the sem_wait() function?

P() operation in Dijkstra’s semaphore notation.

22
New cards

What does sem_post() correspond to in semaphore operations?

V() operation in Dijkstra’s semaphore notation.

23
New cards

What is the result of calling sem_trywait() on a semaphore that's not available?

It returns EAGAIN.

24
New cards

Where are POSIX semaphores declared?

In semaphore.h.

25
New cards

What is the primary difference between POSIX semaphores and System V semaphores?

POSIX semaphores are considered an improvement and obsolete System V semaphores.

26
New cards

What header file is required for working with Pthreads?

pthread.h.

27
New cards

What happens to waiting threads when a condition variable is signaled?

The sleeping threads are awakened.

28
New cards

What function can be used to destroy a condition variable?

pthread_cond_destroy().

29
New cards

What is one key requirement for using a condition variable?

A thread must hold a mutex to wait on it.

30
New cards

Which function creates a condition variable?

pthread_cond_init().

31
New cards

What is a potential risk when destroying a condition variable?

Doing so while there are waiting threads is an error.

32
New cards

What is the typical behavior of a condition variable across different Pthreads implementations?

It typically has no attributes recognized by Linux.

33
New cards

What is a unique feature of recursive mutexes?

They maintain a lock count.

34
New cards

What does pthread_cond_broadcast() do?

Signals all waiting threads.

35
New cards

What is the return type of a thread start function?

void*.

36
New cards

What should you check before destroying a mutex or condition variable?

Ensure no threads are using or waiting on it.

37
New cards

What is the role of pthread_attr_t in thread management?

To specify various thread attributes like scheduler and stack size.

38
New cards

What is indicated by the term 'deadlock'?

A situation where two or more threads cannot proceed because each is waiting for the other to release resources.