hi,
I have 3 threads in my program but without mutex. Now the problem is that the 3th thread stops looping...
Do I have to use mutex and how does it work for 3 threads
Code:
static char buffer[64][255]
static char buffer2[30][3000]
/* in the main */
iret1 = pthread_create(&thread1,NULL,(void*)&read_port,NULL);
iret2 = pthread_create(&thread2,NULL,(void*)&read_buffer,NULL);
iret3 = pthread_create(&thread3,NULL,(void*)&split_buffer,NULL);
pthread_join(thread1,NULL);
pthread_join(thread2,NULL);
pthread_join(thread3,NULL);
/* thread 1 */
for(EVER){
res=read(fd,buf,255);
buf[res]=0;
if(res > 0){
strcat(buffer[i],buf);
i++;
if(i==64){
i=0;
}
}
}
/* thread 2 */
for(EVER){
if(a!=i){
/* here i get data out of first buffer and put it into second buffer */
}
}
/* thread 3 */
for(EVER){
if(j!=c){
/* here i read from the second buffer, split it in pieces and write to database */
}
}