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
Didn't find your answer? Ask the community — no account required.
H
Hans-Bernhard Broeker
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.
A
Anthony Fremont
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 ;-)
S
Spehro Pefhany
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
S
Spehro Pefhany
It's got to at least be a static flag, maybe more if the ISR is designed to be re-entrant.
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
G
Genome
No,
As you know.... and I don't,
You deal with interrupts on the basis of priority which means an interrupt with higher priority interrupts the original interrupt.
After dealing with the important interrupt then the system 'fallsback' to deal with the original interrupt(s)..... in order of prioratisation.
A 'callback' is a check to see if the nonprioritised thing that went 'squeek' really needed stroking in the first place.
DNA
F
Frank Bemelman
"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)
F
Fred Bloggs
Sounds simple enough- think I used something similar long before there ever was such a word.
F
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?
J
John Larkin
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
A
Anthony Fremont
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.
J
John Larkin
This is bare-metal assembly on a single-chip uP without MMU. Everything's global, and everything's static. The isr runs periodically at about 10 KHz, and just runs straight through to completion every time, with some simple state flags to direct its path. There's a block I *should* run every 5th time, but if something more important needs to be done (namely collecting some energy readings every time a laser fires) I set a flag to remind me to do the deferred stuff some later pass.
Thanks to all for the "callback" explanation.
John
J
John Larkin
Little ticktock state machines can be very powerful in the right circumstances. And very reliable.
John
F
Fred Bloggs
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.
F
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.
M
Martin Riddle
Its funny how many answers it takes. ;D
J
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
J
John Larkin
AKA "pure" code.
John
J
John Larkin
So any code that's ever run more than once is "re-entrant"?
John
A
Anthony Fremont
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.
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.