Posted by : ANIL KUMAR MULA Monday, 17 November 2014

this is a description of CSP.















/*
Cigarette smokers problem implemented using threads
Thread synchronization was done using semaphore
To treminate the program Each smoker is given two rounds of smoking

*/
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<semaphore.h>
#include<pthread.h>
int table_used=1,generated_item[2],generated=0;
char *item[]={"tubaco","paper","matches"};
sem_t table;
void *agent(void *arg)
{
// agent thread function that has infinite number of ingredians
int i,j,k=0;
int count=0;
while(1)
{
sleep(1);
sem_wait(&table);
if(count==6) exit(0);
if(table_used==1)
{
i=k;
j=i+1;
if(j==3)
j=0;
k=j;
generated_item[0]=i;
generated_item[1]=j;
printf("agent produces %s,%s\n",item[i],item[j]);
generated=1;
table_used=0;
count++;
}
sem_post(&table);

}
}
void *smokeri(void *i)
{
//int count=0;
while(1)
{
sleep(1);
sem_wait(&table);
if(table_used==0)
{
if(generated && generated_item[0]!=(int)i &&
generated_item[1]!=(int)i)
{
printf("SMOKER%d completed his smoking\n",(int)i);
printf("\n");
//count++;
table_used=1;
generated=0;
}
}
sem_post(&table);
//if(count==5) exit(0);
}
}
main()
{
pthread_t smoker1,smoker2,smoker0,agnt;
sem_init(&table,0,1);
printf("SMOKER0 has tobacco\n");
printf("SMOKER1 has paper\n");
printf("SMOKER2 has matches\n");
pthread_create(&agnt,0,agent,0);
pthread_create(&smoker0,0,smokeri,(void*)0);
pthread_create(&smoker1,0,smokeri,(void*)1);
pthread_create(&smoker2,0,smokeri,(void*)2);
while(1);
}

{ 3 comments... read them below or Comment }

  1. Marijuana—also called weed, herb, pot, grass, bud, ganja, Mary Jane, and a vast number of other slang terms—is a greenish-gray mixture of the dried flowers of Cannabis sativa.

    The main active chemical in marijuana is THC (delta-9-tetrahydrocannabinol), the psychoactive ingredient. The highest concentrations of THC are found in the dried flowers, or buds. When marijuana smoke is inhaled, THC rapidly passes from the lungs into the bloodstream and is carried to the brain and other organs throughout the body. THC from the marijuana acts on specific receptors in the brain, called cannabinoid receptors, starting off a chain of cellular reactions that finally lead to the euphoria, or "high" that users experience. Feeling of a relaxed state, euphoria, and an enhanced sensory perception may occur. With higher THC levels in those who are not used to the effects, some people may feel anxious, paranoid, or have a panic attack.
    Cannabis plant used for medical or recreational purposes. The main psychoactive part of cannabis is tetrahydrocannabinol, one of the 483 known compounds in the plant, including at least 65 other cannabinoids. 
    buy real weed online
    how to buy weed online
    buy legal weed online
    buy recreational weed online
    buy weed edibles online
    can i buy weed online
    buy medical weed online
    buy weed online canada
    buying weed online reviews
    buy weed online legit
    buy weed online without medical card
    buy weed seeds online canada
    order marijuana online
    order marijuana seeds online
    how to order marijuana online
    order marijuana online without a medical card
    can you order medical marijuana online
    order marijuana online

    ReplyDelete

  2. A psilocybin mushroom, also known as a magic mushroom or a psychedelic mushroom,
    buy mushroom online
    is one of a polyphyletic group of fungi that contain psilocybin and psilocin.



    Buy Pink Runtz Online Best Place To Buy JokesUp Runtz and Cookies Weed Jar is at CookiesxRuntz ,
    Buy Pink Runtz Online
    We’re #1 in the Market Having All latest strains and flavor’s of Pink Runtz,White Runtz and Cookies Weed.


    Get in Touch with Us for the Best Quality Of Driver's License & IDs
    BUY FAKE IDs ONLINE
    All of Driver’s License or Fake IDs comes with Scannable Features & Guaranteed to Pass Under UV Without any Hassle.

    ReplyDelete
  3. thanks for a very important information about delta 9 cartridgeDelta 9 thc cartridge
    Delta 9 thc cartridge near me
    Delta 9 thc cartridge ,we also have available interesting articles that my help your customers fund interesting informations about the above mentioned produtc(delta 9 catridge)for more information,kindly reach out to us via the following listed contact details below

    call/text/Whatsapp........+1(505)257-5355
    Email: support@legal420isolate.com

    ReplyDelete

- Copyright © Anil Kumar Mula - Skyblue - Powered by Blogger - Designed by Johanes Djogan -