Okay so i justed check the return value and its -1....... which i guess is an error but cant figure it out.
Code:
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void * thread2(void*);
void * thread1(void*);
int commpipe[2];
int sndpipe[2];
int rv, dv;
int looper,i ;
char buf [30];
char* bug;
#define NUM_THREADS 2
pthread_t tid[NUM_THREADS]; /* array of thread IDs */
int main(){
char * buffer = "hello my tester\n";
if (pipe( commpipe ) ) {
fprintf(stderr,"Pipe error!\n");
exit(1);
}
if (pipe( sndpipe ) ) {
fprintf(stderr,"Pipe error!\n");
exit(1);
}
pthread_create(&tid[1], NULL, thread1, NULL);
pthread_create(&tid[0], NULL, thread2, NULL);
write(sndpipe[1],buffer,100);
//write(sndpipe[1],"hello test2 ",15);
//write(sndpipe[1],"hello test 3",15);
//write(sndpipe[1],"mark as test4",15);
//sleep(7);
write(commpipe[1], "test", 5);
sleep(2);
printf("Hello\n");
sleep(2);
printf("Goodbye\n");
sleep(2);
printf("exit\n");
for ( i = 0; i < NUM_THREADS; i++)
pthread_join(tid[i], NULL);
fprintf(stderr,"Child exited with a %d value\n",rv);
return 0;
}
void * thread1(void* parm){
sleep(5);
read(commpipe[0], buf, 5);
printf("%s pipe output\n",buf);
pthread_exit(0);
}
void* thread2(void* parm){
sleep(6);
read(sndpipe[0], bug,100);
//printf("%s\n",bug);
read(sndpipe[0], bug,100);
//printf("%s\n",bug);
for(looper =0; looper < 5; looper++){
sleep(1);
printf("GOSH\n");
}
pthread_exit(0);
}