Skip to content Skip to navigation

Connexions

You are here: Home » Content » Draft

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Recently Viewed

This feature requires Javascript to be enabled.

Draft

Module by: Bri

Atomicity

Example 1: C-level Atomicity


thread0: x=x+1
thread1: x=x*2
Figure 1: There are two possible traces, as either thread could execute first.
Subfigure 1.1Subfigure 1.2
Subfigure 1.1 (ex1new.png)Subfigure 1.2 (ex1new2.png)

Example 2: Assembly-level Atomicity


thread0: r0=x, inc r0, x=r0
thread1: r1=x, shiftl r1, x=r1
Figure 2: With finer-grained atomicity, there are many more ways to interleave the threads.
Subfigure 2.1
Subfigure 2.1 (ex1bnew.png)
Subfigure 2.2
Subfigure 2.2 (ex1bnew2.png)

1. /* thread0: x=x+1, using r0 */
2. ld x, r0;
3. inc r0;
4. st r0, x;
5. /* END thread0 */

6. /* thread1: x=x*2, using r1 */
7. ld x, r1;
8. shiftl r1;
9. st r1, x;
10 /* END thread1 */
Figure 3
Figure 3 (assemblysample.png)

Modeling

Example 3: A Tiny First Program


1. show int balance = 0;    /* A variable shared between all processes. */

2. active proctype deposit()
3. {
4.   balance++;
5. }

6. active proctype withdraw()
7. {
8.   balance--;
9. }
Figure 4: There are six possible traces for the above code
Figure 4 (ex0new.png)

Race Conditions

Example 4: A Race Condition


 1. show int balance = 0;    /* A variable shared between all processes. */

 2. active proctype deposit()
 3. {
 4.   show int new_bal;

 5.   new_bal = balance;
 6.   new_bal++;
 7.   balance = new_bal;
 8. }
 
 9. active proctype withdraw()
10. {
11.   show int new_bal;

12.   new_bal = balance;
13.   new_bal--;
14.   balance = new_bal;
15. }
Figure 5: Two possible traces for the above code.
Subfigure 5.1Subfigure 5.2
Subfigure 5.1 (ex2new.png)Subfigure 5.2 (ex2new2.png)

Comments, questions, feedback, criticisms?

Send feedback