Thread functions
threads/thread.c
implements several public functions for thread support. Let’s take a look at the most useful ones for this project:
void thread_init (void)
Called by
main()
to initialize the thread system. Its main purpose is to create astruct thread
for Pintos’s initial thread. This is possible because the Pintos loader puts the initial thread’s stack at the top of a page, in the same position as any other Pintos thread.
Before
thread_init()
runs,thread_current()
will fail because the running thread’s magic value is incorrect. Lots of functions callthread_current()
directly or indirectly, includinglock_acquire()
for locking a lock, sothread_init()
is called early in Pintos initialization.
struct thread *thread_current (void)
Returns the running thread.
void thread_exit (void) NO_RETURN
Causes the current thread to exit. Never returns, hence
NO_RETURN
.