Cigarette Smokers Problem - Solution

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)

and the code for smoker i is

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

Read more about this topic:  Cigarette Smokers Problem

Famous quotes containing the word solution:

    “Any solution to a problem changes the problem.”
    —R.W. (Richard William)

    “I herewith commission you to carry out all preparations with regard to ... a total solution of the Jewish question in those territories of Europe which are under German influence.... I furthermore charge you to submit to me as soon as possible a draft showing the ... measures already taken for the execution of the intended final solution of the Jewish question.”
    —Hermann Goering (1893–1946)

    “What is history? Its beginning is that of the centuries of systematic work devoted to the solution of the enigma of death, so that death itself may eventually be overcome. That is why people write symphonies, and why they discover mathematical infinity and electromagnetic waves.”
    —Boris Pasternak (1890–1960)