60 lines
2.2 KiB
Plaintext
60 lines
2.2 KiB
Plaintext
@node Task Documentation
|
|
@appendix Task Documentation
|
|
|
|
This chapter presents a sample assignment and a filled-in design
|
|
document for one possible implementation. Its purpose is to give you an
|
|
idea of what we expect to see in your own design documents.
|
|
|
|
@menu
|
|
* Sample Assignment::
|
|
* Sample Design Document::
|
|
@end menu
|
|
|
|
@node Sample Assignment
|
|
@section Sample Assignment
|
|
|
|
Implement @func{thread_join}.
|
|
|
|
@deftypefun void thread_join (tid_t @var{tid})
|
|
Blocks the current thread until thread @var{tid} exits. If @var{A} is
|
|
the running thread and @var{B} is the argument, then we say that
|
|
``@var{A} joins @var{B}.''
|
|
|
|
Incidentally, the argument is a thread id, instead of a thread pointer,
|
|
because a thread pointer is not unique over time. That is, when a
|
|
thread dies, its memory may be, whether immediately or much later,
|
|
reused for another thread. If thread @var{A} over time had two children
|
|
@var{B} and @var{C} that were stored at the same address, then
|
|
@code{thread_join(@var{B})} and @code{thread_join(@var{C})} would be
|
|
ambiguous.
|
|
|
|
A thread may only join its immediate children. Calling
|
|
@func{thread_join} on a thread that is not the caller's child should
|
|
cause the caller to return immediately. Children are not ``inherited,''
|
|
that is, if @var{A} has child @var{B} and @var{B} has child @var{C},
|
|
then @var{A} always returns immediately should it try to join @var{C},
|
|
even if @var{B} is dead.
|
|
|
|
A thread need not ever be joined. Your solution should properly free
|
|
all of a thread's resources, including its @struct{thread},
|
|
whether it is ever joined or not, and regardless of whether the child
|
|
exits before or after its parent. That is, a thread should be freed
|
|
exactly once in all cases.
|
|
|
|
Joining a given thread is idempotent. That is, joining a thread
|
|
multiple times is equivalent to joining it once, because it has already
|
|
exited at the time of the later joins. Thus, joins on a given thread
|
|
after the first should return immediately.
|
|
|
|
You must handle all the ways a join can occur: nested joins (@var{A}
|
|
joins @var{B}, then @var{B} joins @var{C}), multiple joins (@var{A}
|
|
joins @var{B}, then @var{A} joins @var{C}), and so on.
|
|
@end deftypefun
|
|
|
|
@node Sample Design Document
|
|
@section Sample Design Document
|
|
|
|
@example
|
|
@include sample.tmpl.texi
|
|
@end example
|