Fedora Linux Support Community & Resources Center
  #1  
Old 27th April 2006, 07:28 AM
kolichina_s_s Offline
Registered User
 
Join Date: Apr 2006
Posts: 19
Unhappy Problem With threads ?

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
Reply With Quote
  #2  
Old 27th April 2006, 05:26 PM
c_ryan Offline
Registered User
 
Join Date: Jul 2005
Posts: 37
Did you all the threads started before the loop? Even if your read thread didn't sleep in the 10 seconds, pre-emptive multithreading should give the other threads some CPU. I'd stick in plenty of console/log file output in your threads to aid debugging (assuming you haven't already done so). Why did you set FASYNC?

Last edited by c_ryan; 27th April 2006 at 05:34 PM.
Reply With Quote
  #3  
Old 28th April 2006, 03:52 AM
vagrant Offline
Registered User
 
Join Date: Apr 2006
Posts: 27
Have you thought about using semaphores?
Reply With Quote
  #4  
Old 28th April 2006, 06:26 AM
kolichina_s_s Offline
Registered User
 
Join Date: Apr 2006
Posts: 19
Quote:
Originally Posted by vagrant
Have you thought about using semaphores?
How can semaphore help in this . as threads are getting blocked because of a simple while loop and each of them is performing their own functions

Last edited by kolichina_s_s; 28th April 2006 at 06:34 AM.
Reply With Quote
  #5  
Old 28th April 2006, 07:12 AM
vagrant Offline
Registered User
 
Join Date: Apr 2006
Posts: 27
Well, I guess I'm having a little trouble understanding you.
Reply With Quote
Reply

Tags
problem, threads

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with a threads database in this forum? ppesci Suggestions & Feedback 3 11th September 2007 07:27 PM
top and threads raghu1111 Using Fedora 1 6th February 2006 09:27 PM


Current GMT-time: 09:51 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat