Today : Thu, 09 Jul 20 .


CS537 Student Wiki


Writing

Homeworks

Sections

Projects

Project Discussion

edit SideBar

Homework5

Page: PmWiki.Homework5 - Last Modified : Mon, 16 Nov 09

Due November 17th in section.

  • Consider this code. What is printed on at the line marked LINE A and the line marked LINE B
    #include <pthread.h>
    #include <stdio.h>
    
    int value = 0;
    
    /* the thread */
    void * runner(void * param)
    {
      value = 5;
      pthread_exit(0);
    }
    
    int main(int argc, char * argv[])
    {
      int pid;
      pthread_t tid;
    
      pid = fork();
      if (pid == 0) { /* child process */
        pthread_create(&tid, NULL /* attributes */, runner, NULL /* arg */);
        pthread_join(tid, NULL);
        printf("Child: value = %d\n",value); /* LINE A */
      } else { /* parent process */
        wait(NULL); /* wait for child */
        printf("Parent: value = %d\n",value); /* LINE B */
      }
    }
    
  • Describe two OS data structures (such as a TCB or page table), in which race conditions are possible. Explain how a race condition can occur.
  • One problem with locks is that they can reduce performance: if all threads are waiting for a lock, only one thread can execute. A common solution to this is fine-grained locking, or using separate locks for different variables. When a small number of locks are used, the usage is called coarse-grained locking.
    Consider a hash table that is created out of an array of buckets, and each bucket contains a linked list of items within that bucket. Items are found by hashing a key to one of the buckets and then searching the list within the bucket.
    1. Describe a coarse-grained locking approach to preventing race conditions for the hash table. How many locks do you need, when do you acquire/release each lock?
    2. Describe a fined-grained locking approach to preventing race conditions for the hash table. This approach should allow multiple threads to access the table simultaneously when they do not cause race conditions.
      • Describe when simultaneous access is safe and unsafe
      • Describe when you acquire/release locks and which lock you acquire/release


This page may have a more recent version on pmwiki.org: PmWiki:Homework5, and a talk page: PmWiki:Homework5-Talk.


Powered by PmWiki
Skin by CarlosAB

looks borrowed from http://haran.freeshell.org/oswd/sinorca
More skins here


PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.

More information

Return to http://pages.cs.wisc.edu/~swift/classes/cs537-fa09/wiki/pmwiki.php