1 / 15

CSC369 – tutorial 4

CSC369 – tutorial 4. TA: Trevor Brown Slides: http://www.cs.utoronto.ca/~tabrown/csc369/week4.ppt. UNIX-like Signals. The data structure. In Unix, the signal number represents a bit position in a 32-bit flag in the thread struct Allows a thread to be sent multiple types of signals

gram
Download Presentation

CSC369 – tutorial 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC369 – tutorial 4 TA: Trevor Brown Slides: http://www.cs.utoronto.ca/~tabrown/csc369/week4.ppt

  2. UNIX-like Signals

  3. The data structure • In Unix, the signal number represents a bit position in a 32-bit flag in the thread struct • Allows a thread to be sent multiple types of signals • Positives? • minimal memory space, no dynamic memory allocation needed • just setting a bit is fast… • Negatives? • Signals can be lost. How? • … if two of the same type are sent before the first is handled. UNIX-like Signals

  4. An alternative design? • Create signal queue for each thread • linked list of structs containing a field that identifies the signal type • Get reliable signal delivery, but… • Downsides: • more memory • more time to allocate a struct and queue it up • What should you do? • You are free to design your own mechanism, but • For the signals we are supporting, losing a repeat is not a big deal. • Most people should prefer the simpler design. UNIX-like Signals

  5. The algorithm – how does it work? • How do we send signals? • Using the sys_kill() system call • The signaler (the thread that call sys_kill()): • Set a bit in the target thread • Error check and return • What kinds of things do we do to error check? • Returning: copyin/out • The signaled thread: • Checks its signal flag before returning to user space • Handles any signals that are marked UNIX-like Signals

  6. Some examples of signals • SIGKILL • Order a thread to roll over and die • SIGSTOP • Order a thread to go to sleep • Sleeping beauty style: must wait for prince SIGCONT to wake • SIGCONT • Wake up a thread put to sleep with SIGSTOP UNIX-like Signals

  7. Funny cases and design decisions • Funny cases are design decisions • They should appear in your design document! • What else should appear in your design doc.? • Any time you choose among several algorithms, why? • How does a thread wait for SIGCONT after getting SIGSTOP? • One way: use a condition variable • Recall, a condition variable supports operations: • wait() (suspend the invoking process and release the lock) • signal() (resume exactly one suspended process) • broadcast() (resumes all suspended processes) • We said a signaled thread checked and handles signals before returning to user space… • What if a thread receives a signal in kernel space? • Should a thread immediately die if it receives SIGKILL? UNIX-like Signals

  8. Assignment 2

  9. What are you doing in A2? • In a nut-shell: • Check out the new code (“…/a2” instead of “…/a1”) • Implementing parts of the PID system • noting that pid.c is a monitor which protects access to the PID array! • Implementing missing synchronization functions • thread_join • thread_detach • thread_exit • thread_fork • These must work together! • Implementing missing system calls • getpid • waitpid • kill Assignment 2

  10. Old slides 1/5 Assignment 2

  11. Old slides 2/5 Assignment 2

  12. Old slides 3/5 Assignment 2

  13. Old slides 4/5 Assignment 2

  14. Old slides 5/5 Assignment 2

  15. Some tips for A2 • Look at the new code in kern/thread • Search functionality in an IDE (e.g., NetBeans) makes browsing code (and finding functionality) much easier • Be very thorough. If one person implements, the other should code-read and test. • Read the man pages so you understand the parameters received and errors returned. • Reminders: • pid.c serves as a monitor to an important data structure • getpid and waitpid are user level tools • thread_join and thread_detach are kernel level tools • http://www.cdf.toronto.edu/~csc369h/fall/assignments/a2/a2.shtml Assignment 2

More Related