Skip to content

deepikap1/CS_Problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

CS_Problem

Problem:

There are four processes in this problem: three smoker processes and an agent process. Each of the smoker processes will make a cigarette and smoke it. To make a cigarette requires tobacco, paper, and matches. Each smoker process has one of the three items. I.e., one process has tobacco, another has paper, and a third has matches. The agent has an infinite supply of all three. The agent places two of the three items on the table, and the smoker that has the third item makes the cigarette. Synchronize the processes.

Solution:

This seems like a fairly easy solution. The three smoker processes will make a cigarette and smoke it. If they can't make a cigarette, then they will go to sleep. The agent process will place two items on the table, and wake up the appropriate smoker, and then go to sleep. All semaphores except lock are initialized to 0. lock is initialized to 1, and is a mutex variable.

For Ubuntu

use these commands in terminal for compilation.

How to compile this code:

$ gcc cs.c -o cs -lpthread

how to run this code:

$ ./cs

About

Cigarette Smokers Solution using Semaphores

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors