Hello frnds..

i m using while loops in my code.. bec of that my application uses almost 90% of CPU resources.. its not lettin others applications to run..

actually i have to read some signal from serial port... n till i dont get it high or low..
i have to read that signal continuously... its for this reason i m using while loops.

else if(status==0)

some code


someone suggested me to use sleep in the while loop..
i cant use it bec we are workin on realtime systems...
so we usually avoid using delay n sleep....

can anyone help me on this ???

my application is on C++/fedora

Recommended Answers

All 2 Replies

>>its not lettin others applications to run..

>>i cant use it bec we are workin on realtime systems

Do you mean you can't because the os doesn't support it, or because you don't want to use it? If you want to let other applications run then you aren't making full use of a real-time os.

What operating system is this for anyway?

IMO, the better place for this would be in the driver code, not your user code.

If you're lucky, your hardware will be capable of generating an interrupt when CTS changes.
If not, then making the driver (not your user code) poll the status and only signal your code when it changes would be the next best thing.

Try a specialised distro, not an off the shelf desktop distro

If CTS goes 0 -> 1 -> 0, what is the minimum time it can spend at 1 before you get interested in it (say 1mS)?
You could try usleep() or nanosleep(), but anything which involves the scheduler is going to have variable results at some point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.