Teaching‎ > ‎CS350 Spring 2009 TF‎ > ‎

2009-04-24

posted Apr 24, 2009, 11:01 AM by Site Admin Role
  • Making two threads take turns to print out "Giraffe", "Zebra", "Giraffe", "Zebra", ... (see attachment turns.c below).
    • Thread execution is concurrent by nature.
    • pthread_yield() and sched_yield() only works when another thread is blocked. On uniprocessor system, they can achieve the interleaving effect, but not on multiprocessor system.
    • Don't bother with sleep.
    • Use the "turns" critical section.
  • Array out of bounds access memory corruption (see corrupt.c below).
    • We read a line that is longer than what the buffer could hold, causing array out of bounds access.
    • Some memory is corrupted after the buffer, but that doesn't show during execution.
    • The corruption causes segmentation fault at seemingly unrelated spot in code.
ċ
corrupt.c
(0k)
Site Admin Role,
Apr 24, 2009, 11:09 AM
ċ
turns.c
(1k)
Site Admin Role,
Apr 24, 2009, 11:09 AM
Comments