Spicyztrickz

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

P-thread || C program


#include <pthread.h>
#include <stdio.h>
struct num
{
int thread_num;
int count;
};

void* char_print (void* number)
{

struct num* p = (struct num*) number;
int i = (p->count *(p->count + 1))/2;
printf("Now in thread %d: \n", p->thread_num);
printf("The sum is: %d\n", i);
//fputc (i, stderr);
return NULL;
}

int main ()
{
pthread_t thread1_id;
pthread_t thread2_id;

struct num thread1_args;
struct num thread2_args;
//thread1_args.count = 3;
printf("Enter the number: ");
scanf("%d" , &(thread1_args.count));
thread1_args.thread_num = 1;
pthread_create (&thread1_id, NULL, &char_print, &thread1_args);
pthread_join(thread1_id, NULL);

printf("Enter the number: ");
scanf("%d" , &(thread2_args.count));
thread2_args.thread_num = 2;
pthread_create (&thread2_id, NULL, &char_print, &thread2_args);


pthread_join(thread2_id, NULL);
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