CS 160 Lab 1

Introduction to Concurrent Programming & Threads



Outline of Lab 1

  1. Introduction: T.A. : Yan Luo
    Office: BRNHL A 261 or A212
    Office Hours: Mon 4-5p, Wed 3-4p, Fri 2-3p
  2. Background: What programming skills are required?
    1. C++ basics.
    2. Introduction to void pointers and how to use them.

      A void pointer can point to anything.

      Void pointer vs NULL pointer

      For example,

                void* pointerX;
                void* pointerY;
                char a='a';
                int b=1;
                pointerX = &a;
      	  printf("pointerX = %c\n", *pointerX);
                pointerX = &b;
      	  printf("pointerX = %d\n", *pointerX);
      	  pointerY = NULL;
      	  printf("pointerY = %c\n", *pointerY); // will cause seg fault
          

      Note: be careful of the usage of void pointers.

                void* x;
      	  int a, b, c;
      	  My_Class D;
      
      	  x = &D;
      	  a = b + c + *((int*)(D));
      
          
  3. What are some examples of concurrent programs?
  4. How does concurrent programming differ from standard sequential programming?
    1. Example 1: Two concurrent processes.
    2. Example 2: Problems with concurrency.
  5. Examining the code. How does it work?


The following links are the code segments we will be examining and running. The following links are online tutorials. Lecture notes of this lab session