Re: query about printf



On 28 May 2008 at 12:27, Rahul wrote:
I had a query reg printf(). I heard that it can't be used in ISR's as
it is non-re-enterant. I didn't get as to why printf is
non-re-enterant and why non-re-enterant library can't be used in an
ISR?

I believe POSIX requires the functions that write to streams to be
implemented in a re-entrant way (certainly this will be true if you're
using threads)... In general I don't think the famous ANSI C Standard
(praise be upon it!) insists on it. It's easy to imagine an
implementation of printf() that used a static internal buffer to build
up the string before sending it to stdout, for example.

If you call a non-reentrant function from an ISR, what if the code you
interrupted was another call to the same function? You'd likely corrupt
both the interrupted function's data and the data in the function called
by your ISR.

In any case, calling printf() in an ISR is almost certainly a mistake,
reentrant or not. Latency considerations mean that you really don't want
to be calling big bloated functions like printf() inside an ISR - you
would be blocking further interrupts for far too long.

.



Relevant Pages

  • Re: Calling sprintf from interrupt context
    ... So better not to use it from ISR, ... For debugging purpose printf can be used. ... it is ISR safe. ...
    (comp.os.vxworks)
  • Re: ISR servicing
    ... Servicing an ISR after my time out interval. ... Can any body help me out why a single printf() or a func call in an ... func() call i am unable to serivce an ISR ... Not sure if by watchdog you mean a board watchdog that reboots the board if it is not frequently pinged of if you mean the standard vxWorks watchdogs from wdLib. ...
    (comp.os.vxworks)
  • Re: query about printf
    ... version of printf uses a static buffer or a global buffer. ... In C there is no such thing as an "ISR" and there is only one ...
    (comp.lang.c)
  • Which functions can I call from an ISR(Interrupt Service Routine)
    ... functions that can be called from an interrupt service routine, ISR. ... Standard functions like printf and so on cannot be used because blocking can ...
    (microsoft.public.windowsce.platbuilder)
  • query about printf
    ... I had a query reg printf(). ... as it is non-re-enterant. ... used in an ISR? ...
    (comp.lang.c)