Hi,
I am working with around 8 threads. In each thread I am running a while loop. in thread "1" I am writing to the serial port and in thread "2" I am reading from the serial port. the problem is that writing to port is getting resolved quickly but reading from the port in the second thread is done through select() with a time out of 10 seconds. and this whole waiting is in a loop. and as long as this loop is running I am not able to switch to other threads. once this entire loop is finished then other threads get their time quantum and end them selves. Why is this so ? here is how the sample code looks for thread "2"
fcntl(fd_for_Serailport,... , FASYNC);
int x = 0;
while(x!=10) {
select(fd_for_Serailport,NULL,...,timeout); // timeout 10 secs.
if(FD_ISSET(fd_for_Serailport)) {
ReadPort();
}
else {
puts("timeout");
}
sleep(10);// even if I keep it to sleep it is not giving control other threads
x++;
}
void ReadPort()
{
just reads data from the Port and prints it.
}
Can I set the time quantum of the threads manually ? or what else i can do to avoid this problem . I am using posix threads , Please Help.
Thanks