All pastes #2113628 Raw Edit

Unnamed

public text v1 · immutable
#2113628 ·published 2012-02-09 06:10 UTC
rendered paste body
2.1 If you program in C, read the documentation for pthread_cancel. Using this information and the model provided in Figure 2.4 on page 26,
write a program where the initial (main) thread creates a second
thread. The main thread should read input from the keyboard, waiting until the user presses the Enter key. At that point, it should kill
o the second thread and print out a message reporting that it has
done so. Meanwhile, the second thread should be in an innite loop,
each time around sleeping five seconds and then printing out a mes-sage. Try running your program. Can the sleeping thread print its
periodic messages while the main thread is waiting for keyboard in-put? Can the main thread read input, kill the sleeping thread, and
print a message while the sleeping thread is in the early part of one of
its five-second sleeps?