2009-04-24

Post date: Apr 24, 2009 6:01:39 PM

    • 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.