<< Chapter < Page Chapter >> Page >

How many possible traces does this code allow? (Try it in SPIN!)

This code has 70 possible traces many more than the previous version. Even with such a smallprogram, it is too cumbersome to try to list them all. This is a fundamental reason why it is so hard for humansto debug a concurrent program, since it involves understanding all the possible ways threads can interact.Once we start using SPIN as a verifier, letting it enumerate these as a part of verification will be oneof the benefits of automation. Later, we will verify this specific example .

More importantly, what is the result of the computation, i.e. , the value of bal at the end?

It can be 0, as expected, but it can also be 1 or -1! These new possibilities are the result of traces such as thefollowing:

Two possible traces for the above program resulting in undesired non-zero results.

In particular, after one process has updated and printed the global variable, the other process can update it based upon the original un-updated value .

Each of the previous two exercises could be very easily answered, if you were given the program's state space.Draw the state space.

State space for above program. For brevity, the variable names are elided.This leaves the information in the form of the deposit and withdraw line numbers and the values of bal , deposit 's new_bal , and withdraw 's new_bal , respectively.

Whew! See how much larger this is than the state space of simpler version of this program .

Making the atomicity more fine-grained increases the possibility of concurrency problems. We will use this idea in many of theexamples in this module, because we want to ensure that we can handle even the hard problems. The particular code sequence used inthe previous example is also one of the shortest with a race condition.

A race condition variation

In Promela, initialization of a variable and assigning to a variable have subtly different semantics.This is illustrated by this variation on the previous example .

1 /* A variable shared between all processes. */ 2 show int bal = 0;3 4 active proctype deposit()5 { 6 show int new_bal = bal;7 8 new_bal++;9 bal = new_bal; 10 }11 12 active proctype withdraw()13 { 14 show int new_bal = bal;15 16 new_bal--;17 bal = new_bal; 18 }

In Promela, initializing variables is part of starting a process. Thus, all variables of all active processes are initialized(defaulting to 0) before any other statements are executed. Here, each copy of new_bal starts with the value 0, so bal always ends with either the value 1 or -1, but never 0.

State space for above program with local variable initializations.For brevity, the variable names are elided. This leaves the information in the form ofthe deposit and withdraw line numbers and the values of bal , deposit 's new_bal , and withdraw 's new_bal , respectively.

Questions & Answers

Ayele, K., 2003. Introductory Economics, 3rd ed., Addis Ababa.
Widad Reply
can you send the book attached ?
Ariel
?
Ariel
What is economics
Widad Reply
the study of how humans make choices under conditions of scarcity
AI-Robot
U(x,y) = (x×y)1/2 find mu of x for y
Desalegn Reply
U(x,y) = (x×y)1/2 find mu of x for y
Desalegn
what is ecnomics
Jan Reply
this is the study of how the society manages it's scarce resources
Belonwu
what is macroeconomic
John Reply
macroeconomic is the branch of economics which studies actions, scale, activities and behaviour of the aggregate economy as a whole.
husaini
etc
husaini
difference between firm and industry
husaini Reply
what's the difference between a firm and an industry
Abdul
firm is the unit which transform inputs to output where as industry contain combination of firms with similar production 😅😅
Abdulraufu
Suppose the demand function that a firm faces shifted from Qd  120 3P to Qd  90  3P and the supply function has shifted from QS  20  2P to QS 10  2P . a) Find the effect of this change on price and quantity. b) Which of the changes in demand and supply is higher?
Toofiq Reply
explain standard reason why economic is a science
innocent Reply
factors influencing supply
Petrus Reply
what is economic.
Milan Reply
scares means__________________ends resources. unlimited
Jan
economics is a science that studies human behaviour as a relationship b/w ends and scares means which have alternative uses
Jan
calculate the profit maximizing for demand and supply
Zarshad Reply
Why qualify 28 supplies
Milan
what are explicit costs
Nomsa Reply
out-of-pocket costs for a firm, for example, payments for wages and salaries, rent, or materials
AI-Robot
concepts of supply in microeconomics
David Reply
economic overview notes
Amahle Reply
identify a demand and a supply curve
Salome Reply
i don't know
Parul
there's a difference
Aryan
Demand curve shows that how supply and others conditions affect on demand of a particular thing and what percent demand increase whith increase of supply of goods
Israr
Hi Sir please how do u calculate Cross elastic demand and income elastic demand?
Abari
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Model checking concurrent programs. OpenStax CNX. Oct 27, 2005 Download for free at http://cnx.org/content/col10294/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Model checking concurrent programs' conversation and receive update notifications?

Ask