I see, I'll put it back in then. Like this right? BTW the for loop is just there instead of sending of packets from a pre made queue.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
pthread_cond_t DataReady = PTHREAD_COND_INITIALIZER;
bool ready = 0;
pthread_mutex_t Lock = PTHREAD_MUTEX_INITIALIZER;
void *consumer(void *Data){
int i;
for(i = 1; i <= 10; i++){
pthread_mutex_lock(&Lock);
while(!ready)
pthread_cond_wait(&DataReady, &Lock);
printf("Sending packet %d: %s", i, (char*)Data);
ready = false;
pthread_mutex_unlock(&Lock);
}
}
void get_input(char *Data){
while(1){
fgets(Data, 100, stdin);
pthread_mutex_lock(&Lock);
ready = true;
pthread_cond_signal(&DataReady);
pthread_mutex_unlock(&Lock);
}
}
int main()
{
char Data[100];
pthread_t a;
pthread_create(&a, NULL, consumer, Data);
get_input(Data);
return 0;
}
Thanks