Maker Pro
Maker Pro

what's a callback?

J

John Larkin

Jan 1, 1970
0
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
 
H

Hans-Bernhard Broeker

Jan 1, 1970
0
[F'up2 cut down --- should have been done by OP!]

In comp.arch.embedded John Larkin said:
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?

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.
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."

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

Anthony Fremont

Jan 1, 1970
0
John said:
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'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'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."

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

Jan 1, 1970
0
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

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
 
G

Genome

Jan 1, 1970
0
John Larkin said:
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

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

Jan 1, 1970
0
John Larkin said:
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.

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.
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."

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 ;)
 
F

Fred Bloggs

Jan 1, 1970
0
Frank said:
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.

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

Fred Bloggs

Jan 1, 1970
0
John said:
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

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

Jan 1, 1970
0
No- that is called "setting a flag to remind you to finish some chores"
and is an example of *re-entrant code*:)

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.
Why in the world would that be
called "callback" unless you collect useless jargon?

Well, I like to learn things. Sorry.

John
 
A

Anthony Fremont

Jan 1, 1970
0
Fred Bloggs said:
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?

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

Jan 1, 1970
0
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.

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

John
 
F

Fred Bloggs

Jan 1, 1970
0
John said:
The isr is not re-entrant.

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."
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.

Right- so that would be interleaved calls.
 
F

Fred Bloggs

Jan 1, 1970
0
Anthony said:
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.

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.
 
J

John Larkin

Jan 1, 1970
0
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.

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

Jan 1, 1970
0
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.


AKA "pure" code.

John
 
J

John Larkin

Jan 1, 1970
0
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.


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

John
 
A

Anthony Fremont

Jan 1, 1970
0
Fred said:
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.

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.
 
F

Fred Bloggs

Jan 1, 1970
0
John said:
So any code that's ever run more than once is "re-entrant"?

John

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.
 
F

Frank Bemelman

Jan 1, 1970
0
Fred Bloggs said:
Sounds simple enough- think I used something similar long before there
ever was such a word.

It is a simple concept. I think the word 'hook was more common with
hardware interrupts or hardware related bios calls. Later, with
graphical user interfaces, Apple Mac and GEM, these mechanisms were
named callbacks. I guess, under that name they must be around for
20-25 years...
 
Top