what's a callback?
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
what's a callback?
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System
Author Message
John Larkin
Guest





Posted: Mon Dec 20, 2004 1:09 am    Post subject: what's a callback? Reply with quote

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
Back to top
Hans-Bernhard Broeker
Guest





Posted: Mon Dec 20, 2004 1:20 am    Post subject: Re: what's a callback? Reply with quote

[F'up2 cut down --- should have been done by OP!]

In comp.arch.embedded John Larkin <john@spamless.usa> wrote:
Quote:
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.

Quote:
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.

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





Posted: Mon Dec 20, 2004 1:26 am    Post subject: Re: what's a callback? Reply with quote

John Larkin wrote:
Quote:
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.

Quote:
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 ;-)
Back to top
Spehro Pefhany
Guest





Posted: Mon Dec 20, 2004 1:43 am    Post subject: Re: what's a callback? Reply with quote

On Sun, 19 Dec 2004 12:09:55 -0800, the renowned John Larkin
<john@spamless.usa> wrote:

Quote:
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
--
"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
Back to top
Spehro Pefhany
Guest





Posted: Mon Dec 20, 2004 1:54 am    Post subject: Re: what's a callback? Reply with quote

On 19 Dec 2004 20:20:59 GMT, the renowned Hans-Bernhard Broeker
<broeker@physik.rwth-aachen.de> wrote:

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

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
Back to top
Genome
Guest





Posted: Mon Dec 20, 2004 2:04 am    Post subject: Re: what's a callback? Reply with quote

"John Larkin" <john@spamless.usa> wrote in message
news:2onbs01b2vcbsmls7bd7qqdlo8kvafuolk@4ax.com...
Quote:
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
Back to top
Frank Bemelman
Guest





Posted: Mon Dec 20, 2004 2:18 am    Post subject: Re: what's a callback? Reply with quote

"John Larkin" <john@spamless.usa> schreef in bericht
news:2onbs01b2vcbsmls7bd7qqdlo8kvafuolk@4ax.com...
Quote:
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.

Quote:
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 ;)

--
Thanks, Frank.
(remove 'q' and 'invalid' when replying by email)
Back to top
Fred Bloggs
Guest





Posted: Mon Dec 20, 2004 2:26 am    Post subject: Re: what's a callback? Reply with quote

Frank Bemelman wrote:
Quote:
"John Larkin" <john@spamless.usa> schreef in bericht
news:2onbs01b2vcbsmls7bd7qqdlo8kvafuolk@4ax.com...

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.

Sounds simple enough- think I used something similar long before there
ever was such a word.
Back to top
Fred Bloggs
Guest





Posted: Mon Dec 20, 2004 2:32 am    Post subject: Re: what's a callback? Reply with quote

John Larkin wrote:
Quote:
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?
Back to top
John Larkin
Guest





Posted: Mon Dec 20, 2004 2:44 am    Post subject: Re: what's a callback? Reply with quote

On Sun, 19 Dec 2004 21:32:42 GMT, Fred Bloggs <nospam@nospam.com>
wrote:

Quote:


John Larkin wrote:
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*:-)

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.

Quote:
Why in the world would that be
called "callback" unless you collect useless jargon?

Well, I like to learn things. Sorry.

John
Back to top
Anthony Fremont
Guest





Posted: Mon Dec 20, 2004 2:50 am    Post subject: Re: what's a callback? Reply with quote

"Fred Bloggs" <nospam@nospam.com> wrote in message

Quote:
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.
Back to top
John Larkin
Guest





Posted: Mon Dec 20, 2004 2:52 am    Post subject: Re: what's a callback? Reply with quote

On Sun, 19 Dec 2004 15:54:38 -0500, Spehro Pefhany
<speffSNIP@interlogDOTyou.knowwhat> wrote:

Quote:
On 19 Dec 2004 20:20:59 GMT, the renowned Hans-Bernhard Broeker
broeker@physik.rwth-aachen.de> wrote:

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

It's got to at least be a static flag, maybe more if the ISR is
designed to be re-entrant.



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
Back to top
John Larkin
Guest





Posted: Mon Dec 20, 2004 2:54 am    Post subject: Re: what's a callback? Reply with quote

On Sun, 19 Dec 2004 15:43:11 -0500, Spehro Pefhany

<speffSNIP@interlogDOTyou.knowwhat> wrote:

Quote:
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
Back to top
Fred Bloggs
Guest





Posted: Mon Dec 20, 2004 2:54 am    Post subject: Re: what's a callback? Reply with quote

John Larkin wrote:
Quote:
On Sun, 19 Dec 2004 21:32:42 GMT, Fred Bloggs <nospam@nospam.com
wrote:



John Larkin wrote:

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*:-)


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

Quote:
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.
Back to top
Fred Bloggs
Guest





Posted: Mon Dec 20, 2004 3:00 am    Post subject: Re: what's a callback? Reply with quote

Anthony Fremont wrote:
Quote:
"Fred Bloggs" <nospam@nospam.com> wrote in message


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.


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.
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 1 of 10

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB