what's a callback?

A few programmers I've known have used the term "callback", which somehow related to executing a deferred subroutine or something. Does anybody know anything about this term or its conventions? If I google it, I just get a lot of telephone-type references.

I'm doing a thing now where, in an interrupt service routine, if I think I'm out of time I set a flag to remind me to finish some chores next time or so. I'm not sure if that qualifies as a "callback."

John

Reply to
John Larkin
Loading thread data ...

The isr is not re-entrant. It just runs periodically to completion (in about 12 usec) and takes various paths each run, depending on what needs to be done. The flag makes sure I get all the necessary stuff done, sooner or later.

Well, I like to learn things. Sorry.

John

Reply to
John Larkin

Little ticktock state machines can be very powerful in the right circumstances. And very reliable.

John

Reply to
John Larkin

That's all nice, but my isr isn't reentrant and is simply executed periodically and runs to completion every time. There's no os, no multitasking, no nested interrupts, the variables are static, so it can't be re-entered. No interleaving, either, just a couple of conditional branches within the routine.

I've written reentrant code (and reentrant isr's and three multitasking RTOSs) and this ain't.

This is in a 68332 with 8-bit eprom. At startup time, the "prototype" routine is copied from eprom into the CPU internal ram, where it's executed. That's a lot faster.

John

Reply to
John Larkin

AKA "pure" code.

John

Reply to
John Larkin

So any code that's ever run more than once is "re-entrant"?

John

Reply to
John Larkin

AFAIUI, a callback handler is essentially like asychronous logic- it's a routine (that you register with some other piece of software) that gets called when some specific set of conditions arise.

The business of sharing resources between threads in a threaded environment (where you can, for some purposes, pretend that the computer is executing multiple bits of software simultaneously) is fairly complex and involves a lot of fairly odd terminology (mutex, semaphore etc.) Most of my stuff doesn't have an RTOS so neither the facilities or the complexity are there.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

My experience with them is that when a piece of system software loads, such as a device driver, that any application might want to call without knowing where it is located, the driver will load an address in a system table (tied to hardware or software interrupts, perhaps) so the application can find the function when needed.

Reply to
Richard Henry

It's actually quite an established term in software API design, and it means quite the same as its origin did in the realm of telephones: you pass someone a number under which he should call you back, if something particular happens. In computers, that number is usually the address of a function.

The canonical example of a callback function is a comparison function passed to a generic sorting routine like qsort() in the C standard library: you pass this information to qsort(), and whenever qsort() needs to know which of two elements is larger, it'll call back your application under this address to find out.

In more en-vogue terms of software design, the callback is the procedural programmer's way of implementing what the OO guys call an observer pattern.

It doesn't. That's just a flag.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

I'd say that it's usually used when you have some kind of OS running. You often specify the address of a routine to be executed when some kind of I/O is complete. The OS automatically invokes the "callback" routine when whatever was being waited on is complete.

An interrupt handler might be deemed a callback routine, but I tend to think of callbacks as being more of a one-off type of thing.

I would call that a semaphore. (actually, I would call it a switch or a flag; someone with more professional education, or someone in personnel might call it a semaphore ;-)

Reply to
Anthony Fremont

A callback is a function you register (store a pointer in a table, for example) with some sort of scheduling routine that you want run when some event occurs.

In the purest sense of things, ISRs are pieces of code that are called when some (physical) event occurs and are run 'outside' of the scheduled tasks. In many OSs, ISRs are actually split into two parts, the 'bottom' and 'top' halfs. The bottom half is the code that must be run at interrupt time to save I/O data, reset h/w for the next event and set a flag or schedule a task to do further processing for the event. The 'top half' is the scheduled task that completes the processing necessary to handle the event. This might be referred to as a 'callback' in some systems.

--
Paul Hovnanian     mailto:Paul@Hovnanian.com
------------------------------------------------------------------
You can discover what your enemy fears most by observing the
means he uses to frighten you. -- Eric Hoffer
Reply to
Paul Hovnanian P.E.

Sounds simple enough- think I used something similar long before there ever was such a word.

Reply to
Fred Bloggs

No- that is called "setting a flag to remind you to finish some chores" and is an example of *re-entrant code*:-) Why in the world would that be called "callback" unless you collect useless jargon?

Reply to
Fred Bloggs

chores"

be

That's certainly the most unique definition of re-entrancy that I've seen.

When I think of re-entrant code, I think of code that has no local variable storage associated to it. I also think of code that can call itself recursively or be executed in several threads across multiple processors concurrently with only one copy in memory.

Reply to
Anthony Fremont

Yes it is: "Used to describe code which can have multiple simultaneous, interleaved, or nested invocations which will not interfere with each other. This is important for parallel processing, recursive functions or subroutines, and interrupt handling."

Right- so that would be interleaved calls.

Reply to
Fred Bloggs

I am not going to quibble with your high level semantics- if the code can be re-entered to perform its processing to completion then it is re-entrant, period. I am not interested into any universal all-encompassing definitions. It is a *simple* ISR.

Reply to
Fred Bloggs

Its funny how many answers it takes. ;D

Reply to
Martin Riddle

I thought you were referring to the act of him using a flag as being an example of re-entrancy. I didn't know you were refering to the ISR in general.

At any rate, an ISR is not necessarily re-entrant. I would say that most interrupt handlers in the 8/16 bit micro world are not.

Reply to
Anthony Fremont

I am thinking of real-time assembler- you are doing something else. If these tasks to be done have some global status variable indicating the what service tasks have been done and are yet to be done, then a re-entrant ISR which reads this status does what you want.

Reply to
Fred Bloggs

"John Larkin" schreef in bericht news: snipped-for-privacy@4ax.com...

It's when you pass the address of a function to the operating system. Often used to change the standard behaviour of gadgets supplied by the OS, and where only your program 'knows' how it should be done. Such an example is the open-file-box that windows presents, which can have many different 'faces' depending on the application that calls it. Some common options can be changed by simple parameters, but if you want some really odd behaviour, you write the tricky part of the code yourself and use a callback. Also called a hook.

Like you say, it's a flag. An alternative to a single flag could be a stack or queue of 'things that need to be done'. Or un-done ;)

--
Thanks, Frank.
(remove 'q' and 'invalid' when replying by email)
Reply to
Frank Bemelman

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.