Spicyztrickz

Loot Tricks, Free Recharge Tricks, Paytm, Mobile Offer 2019, Unlimited Paytm Cash, Highest Paying Latest Apps & Websites. Best Deals Of The Day.

Semaphore Using P_thread || C program


#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<unistd.h>

sem_t mutex;
int c = 0;

void *thread(void *arg){
 sem_wait(&mutex);
 printf("%d%d\n", c, c);
 c++;
 sem_post(&mutex);
 sleep(1);
}

int main(){
 while(1){
  
  sem_init(&mutex, 0, 1);
  pthread_t t1, t2;
  pthread_create(&t1, NULL, thread, NULL);
  sleep(1);
  pthread_create(&t2, NULL, thread, NULL);
  pthread_join(t1, NULL);
  pthread_join(t2, NULL);
  sem_destroy(&mutex);
 }
 return 0;
}

Post a Comment

[disqus]

MKRdezign

{facebook#https://www.facebook.com/12brahma/} {twitter#https://twitter.com/brahmasanidipak} {google-plus#https://plus.google.com/118318150044608348295} {pinterest#https://in.pinterest.com/spicyztrickz/} {youtube#YOUR_SOCIAL_PROFILE_URL} {instagram#YOUR_SOCIAL_PROFILE_URL}

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget