<< Chapter < Page Chapter >> Page >
Trace
A trace is the sequence of operations (and their data) performed in a particular run of a concurrent program.Equivalently, it is the sequence of states during a run i.e. , the collection of variable and program counter values.
Atomic
An atomic operation is indivisible. A context switch to another process cannot happen during this operation.

Both the syntax and semantics of the concurrency primitives can vary among programming languages and concurrency libraries.We will use a particular language, Promela , which implements the most commonly-used features ofconcurrent programs. In Promela,assignment statements are defined to be atomic. We'll later contrast atomic with non-atomic assignment statements.

Problems with concurrency

Programmers are comfortable with debugging single-threaded code, where most questions involve ``doesthis sequence of instructions compute the correct answer?''Concurrency, however, introduces the added complications of communication and synchronization;a single task may be spread across several sequences of instructions running asynchronously,and multiple threads can interact in unintended ways. The following are five common categories of problems with concurrency.

Deadlock
(Informal) Deadlock is when two or more threads stop and wait for each other.
Livelock
(Informal) Livelock is when two or more threads continue to execute,but make no progress toward the ultimate goal.

Deadlock vs. livelock

As an analogy, consider two people walking in a hallway towards each other. The hallway is wide enough for twopeople to pass. Of interest is what happens when the two people meet.If on the same side of the hallway, a polite strategy is to step to the other side.A more belligerent strategy is to wait for the other person to move. Two belligerent people will suffer in deadlock, glaringface to face in front of each other. Two polite people could suffer from livelockif they repeatedly side-step simultaneously. (No conclusions on morality are to be inferred fromthe fact that one polite and one belligerent person don't have any problems.)

Two belligerent hallway-walkers can deadlock.
Fairness
(Informal) Fairness is the idea that each thread gets a turn to make progress.

There are more specific notions of fairness that describe when and how often threads are guaranteed to get a turn.For example, do we expect that each thread should be executed as often as any other, or is it acceptable if one runs a hundred stepsfor each step of any other thread? When considering fairness, one must also consider the system codeimplementing the threads. The implementation includes a scheduler that determines how to interleave the threads, and the schedulermight or might not provide any fairness guarantees.

Starvation
(Informal) Starvation is when some thread gets deferred forever.

Fairness and starvation

Assume we are modeling a store. Consumers buy products, reducing the shelf inventory. Meanwhile, employees restockthe shelves, increasing the shelf inventory. More simply, let thread C be a loop that repeatedly decrements a counter, and thread P be a loop that repeatedly increments that same counter.

Unless our scheduler (which may be nature) otherwise gives some guarantees,this system does not ensure that the two threads execute fairly.In particular, it is possible for one thread to starve the other.

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