With Already Passed Solutions (Graded
A+)
What is a thread library? - Answer An API that programmers can use to create and manage
threads
How can a thread library be implemented? - Answer User Level - Entirely implemented in user
space. No system calls are made.
Kernel Level - Implemented with kernel support, ie. handled by OS. Typically results in a system
call
What are the main thread libraries used today? - Answer POSIX Pthreads
Windows thread library
Java thread API
What is POSIX? - Answer A family of standards. Used to ensure compatibility between
operating systems.
Defines API behavior, and the shell U/I requirements.
Are POSIX pthreads user level or kernel level? - Answer Can be both. In Linux they are kernel
level.
Is the Windows thread library user level or kernel level? - Answer Kernel level
Is the Java thread API user level or kernel level? - Answer User level in that the thread is
created on the machine itself, but in doing this the Windows thread library or POSIX pthreads
are typically invoked depending on the host OS.
, Typically used for responsive user interfaces.
What is synchronous threading? - Answer The parent thread is not allowed to continue
execution until the children have finished working.
Typically involves significant data sharing between threads.
Where does the first thread begin in a program? - Answer In the main() function
How do threads share data? - Answer Using global variables
What datatype is used to reference a child process? - Answer pid_t, implemented as an int
What datatype is used to reference a child thread? - Answer pthread_t
When we create a thread in C in practice what do we need to do? - Answer Create a pthread_t
object to reference the thread (id)
Create a pthread_attr_t object to reference the attributes of the thread (attr)
------
Call pthread_attr_init(attr) to initialize your attributes
Call pthread_create(id, attr, function, param) which creates the new thread and specifies which
function will be called in the thread, passes in any parameters
Call pthread_join(id) after the create function IF you want the parent to wait for the child to
finish
Call pthread_exit in the child function when you want to end the thread.