Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12620 Discussions

pthreads with timers and with blocking reads

Altera_Forum
Honored Contributor II
944 Views

I&#39;ve found two aspects of ucLinux and pthreads that have left me wondering if (a) there&#39;s something I&#39;m missing or (http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif Linux pthreads are a poor choice for real-time applications. I&#39;m hoping the answer is (a) even if it&#39;s humbling. 

 

First, I&#39;ve been using setitimer, but the only useful timer to me is ITIMER_REAL, which can send only SIGALRM, and all pthreads in a signal application share the same signal function table. So, in effect there&#39;s one real-time timer for the entire application. If I want to separate threads to be able to time out on different events at the same time, I&#39;m hosed, it seems. Does microtronix uClinux have any other timer packages lurking in the library with more capability? To get around the problem as I only need long timeout intervals, I&#39;ve written a crude multi-timer manager thread with a one second resolution. 

 

Second, I have a thread that reads characters one at a time in raw mode from a serial port, ideally blocking (and letting other threads run) if there is nothing to read, timing out after a programmable interval if nothing came in. I&#39;d also like to have this thread run at a high priority. I&#39;ve encountered two problems which I&#39;ve worked out but in suboptimal ways. First, the feature of setting the pseudo-control characters VMIN and VTIME to enable a timeout doesn&#39;t appear to work for the nios uart driver. Second, a blocking read seems to block all threads in the application; the system just locks up forever. So, I have to do a nonblocking read, and unless I throw in a token usleep(1) between read() calls, the high priority thread takes the entire CPU, also locking up the system forever. Running without priorities, preemption passes the CPU among all the tasks and things are hunky-dory, but I&#39;d really like to use priorities to tune the system. 

 

So I&#39;m willing to be humbled in the interest of making this application work the way I&#39;d like it to.
0 Kudos
0 Replies
Reply