0% found this document useful (0 votes)
83 views4 pages

On A Solution To The Cigarette Smoker's Problem (Without Conditional Statements)

Uploaded by

Gözde Nur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views4 pages

On A Solution To The Cigarette Smoker's Problem (Without Conditional Statements)

Uploaded by

Gözde Nur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/234813902

On a solution to the cigarette smoker's problem (without conditional


statements)

Article  in  Communications of the ACM · March 1975


DOI: 10.1145/360680.360709 · Source: DBLP

CITATIONS READS
23 3,736

1 author:

David Parnas
Middle Road Software
303 PUBLICATIONS   19,111 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Effective inspection of software View project

A-7E Software Demonstration View project

All content following this page was uploaded by David Parnas on 15 November 2016.

The user has requested enhancement of the downloaded file.


Introduction

In a widely circulated and referenced m e m o r a n d u m


[1, 2], Suhas Patil has i n t r o d u c e d a s y n c h r o n i z a t i o n
p r o b l e m called the "cigarette s m o k e r ' s p r o b l e m " a n d
Operating C. W e i s s m a n
claimed t h a t the p r o b l e m c a n n o t be solved using the P
Systems Editor
a n d V primitives i n t r o d u c e d by D i j k s t r a [3] unless con-

On a Solution to the d i t i o n a l s t a t e m e n t s are also used. On the basis o f an


e l a b o r a t e p r o o f in terms o f Petri nets, it is c o n c l u d e d

Cigarette Smoker's t h a t the P a n d V primitives are n o t sufficiently p o w e r f u l


a n d t h a t m o r e c o m p l e x o p e r a t i o n s are needed. This

Problem (without con- p a p e r presents a solution to the cigarette s m o k e r ' s


p r o b l e m w i t h o u t c o n d i t i o n a l statements, explicitly

ditional statements) states an implicit a s s u m p t i o n used in Patil's p r o o f , a n d


discusses the need for m o r e p o w e r f u l o p e r a t i o n s .
W h i l e a full i n t r o d u c t i o n into the p r o b l e m can be
D.L. Parnas f o u n d in Patil [1], the aspects o f the p r o b l e m essential
Technische Hochschule Darmstadt to this p a p e r are related below.
T h e r e are three resource classes a n d also three p r o c -
esses using those resources. A t a certain p o i n t in each
process it m u s t have one resource o f each class in o r d e r
This report discusses a problem first introduced by to proceed. I f it does n o t have all three, it m u s t wait
Patil, who has claimed that the cigarette smoker's before proceeding. H o w e v e r , each o f these processes
problem cannot be solved using the P and V operations has a p e r m a n e n t s u p p l y o f one o f the three resources.
introduced by Dijkstra unless conditional statements are ( N o two o f t h e m have a p e r m a n e n t s u p p l y o f the s a m e
used. An examination of Patil's proof shows that he has resource.) There is a set o f processes k n o w n as the agent
established this claim only under strong restrictions which o c c a s i o n a l l y m a k e s two o f the resources available.
on the use of P and V. These restrictions eliminate The one process which has the r e m a i n i n g resource can
programming techniques used by Dijkstra and others then proceed. W h e n it has finished with the three re-
since the first introduction of the semaphore concept. sources it is to notify the agent. The agent will n o t sup-
This paper contains a solution to the problem. It also ply a n y m o r e resources until it receives such notification.
discusses the need for the generalized operators In Patil's d e s c r i p t i o n o f the p r o b l e m the agent is
suggested by Patil. c o n s i d e r e d to be an u n c h a n g e a b l e p a r t o f the p r o b l e m
Key Words and Phrases: o p e r a t i n g systems, co- definition a n d is defined b y the six processes shown
o p e r a t i n g processes, process s y n c h r o n i z a t i o n primitives b e l o w ( n o t a t i o n is c h a n g e d to be consistent with other
CR Categories: 4.3 Communications papers).
r, : P(s); rb : P(s); rc : P s ;
V(b) ; V(a) ; V(a) ;
V(c) ; V(c) ; V(b);
go Io r. ; go to rb ; go to rc ;
B: : P(X); #u : P(Y); 13~ : P(Z);
V(s); V(s) ; V(s);
go to ~?=; go to ~u ; go to Bz ;
Copyright @ 1975, Association for Computing Machinery, Inc. initially s = 1 a n d a, b, c, X , Y a n d Z = 0.
General permission to republish, but not for profit, all or part
of this material is granted, provided that ACM's copyright notice The s e m a p h o r e s a, b, a n d c are used b y the agent to
is given and that reference is made to the publication, to its date r e p o r t the arrival o f the three resources. E a c h s e m a p h o r e
of issue, and to the fact that reprinting privileges were granted d e n o t e s one o f the resources, s is a m u t u a l exclusion
by permission of the Association for Computing Machinery.
This work was supported in part by the Naval Research Labo- s e m a p h o r e to assure t h a t only one p a i r o f resources is
ratory under project WF-15-241-601 and in part by the Advanced d e p o s i t e d at a time. X, Y, Z are to be used by the re-
Research Projects Agency of the Office of the Secretary of Defense source users to r e p o r t t h a t they are d o n e with the re-
(F44620-70-C-0107) and is monitored by the Air Force Office
of Scientific Research, This document has been approved for pub- sources. 1
lic release and sale; its distribution is unlimited. Author's ad- T h e p r o b l e m is stated so as to allow the definition o f
dress: Research Group on Operating Systems I, Fachbereich a n y n u m b e r o f a d d i t i o n a l s e m a p h o r e s and processes
Informatik, Technische Hochschule Darmstadt, Steubenplatz 12,
Darmstadt, West Germany. a n d to use any n u m b e r o f P a n d V statements to write
In the present author's opinion, X, Y and Z could be com- p r o g r a m s for the resource users which will use the re-
bined first with each other and then with s without essentially sources a n d be free o f d e a d l o c k . C o n d i t i o n a l statements
changing the problem. Then the three "beta" processes could be
eliminated. We leave them unchanged because the problem def- are n o t allowed in these p r o g r a m s . Patil states t h a t this
inition has the agent unchangeable. p r o b l e m has n o solution.

181 Communications March 1975


of Volume 18
the ACM Number 3
The Solution (processes and semaphores are in operation appearing in the text operating on a specific
addition to the agent) semaphore determined by the text and fixed throughout
execution of the program.
semaphore mutex; (initially 1)
integer t; (initially 0)
(b) Algol-like sequencing rule with no conditional
semaphore array S[1 : 6]; (initially 0) statements.
~a : P(a); 8b : P(b); ~c PCc) ; (c) Assignment statements with arithmetic expressions
P (mutex) ; P (mutex) ; P (mutex) ; (perhaps allowing quite restricted function calls), but
t ~---t + 1; t ~---t + 2; t~-t+4; no conditional expressions.
V(S[t]) ; V(SIt]); V(S[t]); (d) A set of parallel processes (any number) each
V (mutex) ; V (mutex) ; V (mutex) ; written from elements (a)-(c) above.
go to 6. ; go to 8b ; go to 8c ;
This result, although more restricted than one would
c~ : P(S[6]); c~u : P(S[5]); ,~ P(S[3]); like, is a definite contribution to tl~ state of our
t ~---0; • t ~---0; t ~---0;
knowledge about P and V.
V(X); V(Y); V(Z);
go to as ; go to ~u ; go to .~ ; On a Complication Arising from the Introduction of
Optional: if overflow is a problem Semaphore Arrays
81 : P(S[1]); 8~: P(S[2]); 63 P(S[4]);
go to 61 ; go to ~2 ; go to ~3 ; The use of semaphore arrays does introduce one
The - • • stands for some operations performed by the process. minor complication which has not been discussed in the
literature. In a call of the form "P(S[E])" (where E
Comments represents an arbitrary integer valued expression), the
evaluation of E must take place only once and before
The last three processes are superfluous unless one execution of the body of "P". The evaluation is not
worries about the ill-defined problem of semaphore considered a part of the "primitive" P. (In other words,
overflow. The solution works by simulating a six-branch we must be able to consider the state of the system dur-
case statement using a semaphore array and simple ing evaluation of the expression, whereas we have no
arithmetic operations. The solution is simpler than the information about the state of the system during the
published solution [1] using conditionals. P.J. Courtois execution of a "Primitive" such as " P " or " V " . The
[6] has shown that the extra processes could be elimi- semaphore value will be referenced at least twice. Those
nated by decrementing those semaphores in other interested in programming languages might be in-
processes and adding a semaphores[0]. trigued by the fact that the classical parameter passing
modes found in Algol 60 are inadequate for this purpose.
On Patil's Proof
Were we to want to write an appropriate " P " algorithm
in Algol 60, it would require use of the format P(s,E)
Patil [1] gives a method of representing cooperating
where s is a semaphore array. Only in this way could we
processes as Petri nets, stating that, "the 'transition'
call E by value while being able to refer to s by name
representing the instruction P[S] has an additional arc
We consider this minor difficulty to be a quirk in the
from the place corresponding to semaphore S and from
design of Algol 60 rather than any limitation of the
the transition corresponding to the instruction V[S],
concept of the semaphore.
there is an additional arc to the place corresponding to
the semaphore S." Every element of a semaphore array
On the Yet Unsolved Problem
must be represented by its own place. The transitions
corresponding to V operations may now place markers
It is not the purpose of this paper to suggest that
in any one (but only one) of these places. The descrip-
there are no limitations to the capabilities of Dijkstra's
tion of the action of a Petri net [1] states that a transi-
semaphore primitives. There are limitations of the
tion places markers on all of its output places.
semaphore operations. While we disagree with the
It appears then that Patil has used (but not stated)
result claimed by Patil, we applaud his goal of a precise
an assumption that there are no semaphore arrays.
and substantial evaluation of the Dijkstra primitives•
Since these arrays appeared in the earliest literature on
It is important, however, that such an investigation
the subject [3], the limitation reported by Patil is not a
not investigate the power of these primitives under
limitation on the primitives as they were described by
artificial restrictions• By artificial we mean restrictions
Dijkstra.
which cannot be justified by practical considerations.
Patil's Result In this author's opinion, restrictions prohibiting either
conditionals or semaphore arrays are artificial• On the
Patil has obtained the following result: A solution other hand, prohibition of "busy waiting" is quite
to the cigarette smoker's problem cannot be composed realistic.
given: The justifications given by Patil for eliminating
(a) P and V operations on single s e m a p h o r e s - - e a c h conditional statements are not valid. Some charac-

182 Communications March 1975


of Volume 18
the ACM Number 3
teristics of the definition of the agent are also artificial. can be useful in describing certain processes. I f one
In fact, the agent could be modified to make the prob- wants to describe such processes, one should build the
lem more difficult by removing the restriction that the operations, but they need not be built as "primitives."
agent throws down only two resources and waits until This attitude has been taken by the authors of [5]
they have been taken before adding more [6]. Although where some interesting new upper level operations are
we do not have a solution to that more difficult problem suggested.
(without conditional statements), we do not conclude Patil's generalized operations have been called
that the problem is unsolvable. "parallel" operations because they simulate simul-
An investigation of these questions is difficult be- taneous activities on many semaphore variables. They
cause (1) we have no firm definition of the set of prob- make it easy to describe a single process which does
lems which we wish to be able to solve, and (2) in using tasks which could have been done by several cooperat-
the P V system we have great freedom in the way that we ing sequential processes. Often one finds possibilities
assign tasks to processes and the way that we assign for parallel execution within such processes; these
interpretations to the semaphores in use. Often prob- possibilities cannot be exploited by a multiprocessor
lems which appear unsolvable are easily solved when system because one does not assign two processors to
additional processes or semaphores are introduced. It the same process simultaneously. 2 Often, because of the
would be artificial to rule out such solutions in any potential parallelism within the process, the program
investigation of the capabilities of semaphore primitives. describing the process becomes very c o m p l e x In this
" P " and " V " are deliberately designed so that when sense, the generalized operation is akin to the "go t o "
there are several processes waiting for a " V " operation statement in programming languages. Both add nothing
on a given semaphore, the choice of the process to be to the set of soluble problems; both make it easier to
released by a " V " is not specified. This "nondeter- write programs which should not be written. Those who
minism" is advantageous in writing programs where feel dissatisfied with the P , V primitive system could
schedulers are subject to change or programs are likely look at some " more primitive primitives" suggested by
to be moved to another machine. On the other hand, it Belpair and Wilmotte [8] and Wodon (7).
makes the solution of "priority problems" such as [4] Those interested in further discussions of the ciga-
more difficult. Perhaps exact solutions to some are im- rette smoker's problem itself (including a correctness
possible. The question remains open. Some recent work p r o o f for the solution given here) should read [10].
by Belpaire and Wilmotte [8] and Lipton [9] has helped
narrow the issues. A c k n o w l e d g m e n t . I am indebted to Wing Hing Huen
for helping me to strengthen one of the arguments in
On More Powerful Primitives this paper. I am also grateful to P. Wodon and P.J.
Courtois for helpful comments. An anonymous ref-
Patil's paper ends with the introduction of a "more eree is acknowledged for his lucid description of
powerful" primitive than the " P " and " V " primitives. the proper conclusion of Patil's paper.
His P can simultaneously decrement several semaphores
when all are passable! He suggests that the necessity of Received 1972; revised July 1974
such a primitive is supported by the inability of " P " References
and " V " to solve the smoker's problem. Such proposals 1. Patil, S.S. Limitations and capabilities of Dijkstra's semaphore
are not n e w - - a similar proposal was made when P and Primitives for coordination among processes. Proj. MAC,
V operations were believed insufficient for problems Compdtational Structures Group Memo 57, Feb. 1971.
2. Project MAC. Progress Report, 1970-71.
similar to those solved in [4]. 3. Dijkstra, E.W. Co-operating sequential processes. In
Such arguments are invalid since the problems can be Programm#tg Languages, F. Genuys (Ed.), Academic Press, New
solved. Further, we note that the generalized operation York, 1968. [First published by T.H. Eindhoven, Eindhoven, The
Netherlands, 1965.]
can be p r o g r a m m e d in a straightforward way using P 4. Courtois, P.J., Heymans, F., and Parnas, D.L. Concurrent
and V (and conditionals). control with readers and writers. Comm. ACM 15 (Oct. 1971), 667-
In this author's opinion, the use of the word "primi- 668.
5. Vantilborgh, H., van Lamsweerde, A. On an extension of
tive" to describe routines which might have been called Dijkstra's semaphore primitives. Rep. R192, MBLE, Laboratoire
" m o n i t o r routines" or "operating system service calls" de Recherches, Brussels. Also published in bzformation Processing
suggests that the programs implementing the operations Letters, North Holland Pub. Co., Amsterdam.
6. Courtois, P.J. Private communication.
be small and quickly executed. There are obvious 7. Wodon, P. Still another tool for synchronizing cooperating
practical advantages to placing such restrictions on a processes. Dep. Computer Sci. Rep,, Carnegie-Mellon U.,
code which is the uninterruptable " h e a r t " of an operat- Pittsburgh, Pa., 1972.
8. Belpaire,G., and Willmotte, J.P. Proc. 1973 European
ing system." P " a n d " V" have the desired properties, the ACM Symposium, Davos, Switzerland.
generalized operations do not. 9. Lipton, Richard. On synchronization primitives. Ph.D. Th.,
There is no doubt that the generalized operations, Carnegie Mellon U., Pittsburgh, Pa., June 1973.
10. Habermann, A.N. On a solution and a generalization of the
Such a restriction is the operational definition of "process" cigarette smoker's problem. Techn. Rep., Carnegie-Mellon U.,
or "task" in most operating systems. August 1972.

183 Communications March 1975


of Volume 18
the ACM Number 3

View publication stats

You might also like