Cigarette smokers problem

Cigarette smokers problem

The cigarette smokers problem is a concurrency problem in computer science, originally described in 1971 by S. S. Patil.

Contents

Problem description

Assume a cigarette requires three ingredients to smoke:

  1. Tobacco
  2. Paper
  3. A match

Assume there are also three chain smokers around a table, each of whom has an infinite supply of one of the three ingredients — one smoker has an infinite supply of tobacco, another has an infinite supply of paper, and the third has an infinite supply of matches.

Assume there is also a non-smoking arbiter. The arbiter enables the smokers to make their cigarettes by arbitrarily (nondeterministically) selecting two of the smokers, taking one item out of each of their supplies, and placing the items on the table. He then notifies the third smoker that he has done this. The third smoker removes the two items from the table and uses them (along with his own supply) to make a cigarette, which he smokes for a while. Meanwhile, the arbiter, seeing the table empty, again chooses two smokers at random and places their items on the table. This process continues forever.

The smokers do not hoard items from the table; a smoker only begins to roll a new cigarette once he is finished smoking the last one. If the arbiter places tobacco and paper on the table while the match man is smoking, the tobacco and paper will remain untouched on the table until the match man is finished with his cigarette and collects them.

Argument

Patil's argument was that Edsger Dijkstra's semaphore primitives were limited. He used the cigarette smokers problem to illustrate this point by saying that it cannot be solved with semaphores. However, Patil placed heavy constraints on his argument:

  1. The agent code is not modifiable.
  2. The solution is not allowed to use conditional statements or an array of semaphores.

With these two constraints, a solution to the cigarette smokers problem is impossible.

The first restriction makes sense, as Downey says in The Little Book of Semaphores, because if the agent represents an operating system, it would be unreasonable or impossible to modify it every time a new application came along. However, as David Parnas points out, the second restriction makes almost any nontrivial problem impossible to solve:

It is important, however, that such an investigation [of Dijkstra primitives] not investigate the power of these primitives under artificial restrictions. By artificial we mean restrictions which cannot be justified by practical considerations. In this author's opinion, restrictions prohibiting either conditionals or semaphore arrays are artificial. On the other hand, prohibition of "busy waiting" is quite realistic.

Solution

If we remove the second of Patil's constraints, the cigarette smokers problem becomes solvable using binary semaphores, or mutexes. Let us define an array of binary semaphores A, one for each smoker; and a binary semaphore for the table, T. Initialize the smokers' semaphores to zero and the table's semaphore to 1. Then the arbiter's code is


time.sleep(T)
# choose smokers i and j nondeterministically,
# making the third smoker k
signal(A[k])

and the code for smoker i is

while true:
    time.sleep(A[i])
    # make a cigarette
    signal(T)
    # smoke the cigarette

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Cigarette receptacles — Architek Ash/Trash Receptacle A cigarette receptacle is a container or device for extinguishing and disposal of cigarette waste. Other common names for cigarette receptacle include: ash urn, ash pan, butt receptacles, butt bins, butt holders,… …   Wikipedia

  • Dining philosophers problem — In computer science, the dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them. It was originally formulated in 1965 by Edsger Dijkstra… …   Wikipedia

  • Sleeping barber problem — In computer science, the sleeping barber problem is a classic inter process communication and synchronization problem between multiple operating system processes. The problem is analogous to that of keeping a barber working when there are… …   Wikipedia

  • Readers-writers problem — In computer science, the first and second readers writers problems are examples of a common computing problem in concurrency. The two problems deal with situations in which many threads must access the same shared memory at one time, some reading …   Wikipedia

  • Producer-consumer problem — In computer science, the producer consumer problem (also known as the bounded buffer problem) is a classical example of a multi process synchronization problem. The problem describes two processes, the producer and the consumer, who share a… …   Wikipedia

  • Задача о курильщиках — (англ. Cigarette smokers problem)  проблема синхронизации в информатике, первоначально описанная в 1971 году Сухас С. Патилом[1]. Содержание 1 Ситуация 2 Задача …   Википедия

  • Semaphore (programming) — For other uses, see Semaphore (disambiguation). In computer science, a semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access by multiple processes to a common resource in a parallel… …   Wikipedia

  • Tobacco smoking — Part of a series on Smoking …   Wikipedia

  • Health effects of tobacco — Part of a series on Tobacco …   Wikipedia

  • respiratory disease — ▪ human disease Introduction  any of the diseases and disorders that affect human respiration (respiration, human).  Diseases of the respiratory system may affect any of the structures and organs that have to do with breathing, including the… …   Universalium

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”