CS520
Spring 2013
Laboratory 10
Friday April 12
The lab must be submitted prior to 8am on Saturday April 13.
The first goal for this lab is to complete your implementation
of the thread_create and thread_yield primitives.
The second goal of this lab is to learn how to use timers,
signals and signal handlers.
- Create a program called lab10.c that does the following:
- Initialize a global counter to zero.
- Set up a handler function for the SIGVTALRM signal.
A handler function is a void function that has a single int
parameter, which is the number of the signal that caused it
to be called. When called, the handler function should simply increment
the global counter. Request that your handler function be called for
SIGVTALRM signals by using the library routine
sigaction:
- The first parameter to sigaction should be
SIGVTALRM.
- The second parameter should be the address of a
sigaction struct:
- The sa_handler member of this struct
should be set to the address of your handler function.
- The sa_mask member should be set to the
empty set, by passing the address of the member to
the sigemptyset library routine.
- The sa_flags member should be set to
SA_NODEFER.
- The third parameter should be NULL.
- Initialize a timer to generate a signal every 10 milliseconds
by using the setitimer library routine:
- The first parameter to setitimer should be
ITIMER_VIRTUAL.
- The second parameter should be the address of an
itimerval struct:
- The it_interval member of this struct
should have its tv_sec member set to zero
and its tv_usec member set to 10000.
- The it_value member of this struct should
have its tv_sec member set to zero and its
tv_usec member set to 10000.
- The third parameter should be NULL.
- Create a loop that simply does nothing while waiting for the
global counter to reach 100. When the counter reaches 100, then
the program should exit.
- Be sure to test the return value of all library calls.
Use the perror library routine if an error is
encountered.
- Consult the man pages for the library routines for more
information about them.
- Test your program.
Points will be awarded for this lab in the following way:
- (60 points) Completing thread_create and thread_yield.
- (40 points) Completing lab10.c.
Turn in this laboratory by typing:
% ~cs520/bin/submit lab10 thread.c thread_asm.s lab10.c
Submissions can be checked by typing:
% ~cs520/bin/scheck lab10
Please turn-off any debugging code before you submit your lab.
Remember that there are no late submissions of labs.
Submit what you have prior to 8am on Saturday April 13.
Last modified on April 4, 2013.
Comments and questions should be directed to
hatcher@unh.edu