what's a callback? - Page 2

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: what's a callback?


Quoted text here. Click to load it

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.


Re: what's a callback?

Quoted text here. Click to load it
No, that's just code.

Re-entrant code can be run from multiple threads, and are not
dependent upon one thread running the code to completion
before the other thread can run the same code.

Typically re-entrant code has no side-effects, and no
static variables.  Everything modified typically is in registers
or on the stack, (or perhaps passed as a parameter by
the caller).

All ISRs should be re-entrant, though they needn't be,
if you control your interrupt sources.

Re-entrant code isn't simply an ISR.  When threads
are swapped preemptively, any routine that could
be interrupted and called by another thread needs
to be re-entrant.

I guess that's the same thing I said in the first
paragraph.

Rufus





Re: what's a callback?
Quoted text here. Click to load it

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.


Re: what's a callback?
@nospam.com:

Quoted text here. Click to load it

No, re-entrant code has a specific definition, that is not it, others
have covered it well enough in this thread.

--
Richard

Re: what's a callback?
On Sun, 19 Dec 2004 21:50:21 GMT, "Anthony Fremont"

Quoted text here. Click to load it


AKA "pure" code.

John


Re: what's a callback?
Quoted text here. Click to load it

Well.....I guess if it were to be really pure code, all addresses would
have to be relative to the instruction counter.  ;-)  We used to call
this floatable code as it could be just plunked into memory anywhere and
executed.


Re: what's a callback?
On Mon, 20 Dec 2004 10:12:58 GMT, "Anthony Fremont"

Quoted text here. Click to load it

My (perhaps non-professional-programmer) definition of that is
"relocatable" or "PIC" (position independent) code.

"Pure" code is code that has no associated statics and if of course
not self-modifying, so that it can be executed by multiple threads
without hassle.

John


Re: what's a callback?
callback?', on Mon, 20 Dec 2004:

Quoted text here. Click to load it

A veritable model of recidivism!
--
Regards, John Woodgate, OOO - Own Opinions Only.
The good news is that nothing is compulsory.
We've slightly trimmed the long signature. Click to see the full one.
Re: what's a callback?

Quoted text here. Click to load it

Right. As opposed to "absolute", IIRC.
Quoted text here. Click to load it

"Static" referes to local variables that retain their values between
calls. Static linking of a function (declared in a class
declaration) means that all instances of that class use the same
function at the same location.

My def?

Reentrant code means that a program can have more than one thread
executing concurrently.

http://vergil.chemistry.gatech.edu/resources/programming/threads.html

Eh? Kinda general really.

If you do something to modify a variable and another thread executes
the function it may or may not get a valid value. First,
"concurrently". It's an illusion for a single processor system. They
get a time slice. But when the threads pause, the code where
execution left off is reentered.


--
Best Regards,
Mike

Re: what's a callback?


Quoted text here. Click to load it

Yes, PIC is more common it seems.  I come from the less popular
GE/Honeywell/Bull background.  Actually, the GE part was a little (and I
do mean little) before my time.

Quoted text here. Click to load it

You are right, of course.  ;-)


Re: what's a callback?
The silly thing is that the thread has 'run off' into a whole variety of
code areas not associated with a callback at all...
A 'callback', is exactly what it says, and comes from the useage on the
telephone, where you ring somebody, and they say they will 'call back'.
There are a number of reasons. The first would be the obvious one (I'll
call back, when I have the answer). The advantage here is it removes the
need for an 'interrupt' signal to give a fast response, or a polling
process to monitor the response of the subroutine. It can also be used for
a security application (just as on the phone, where your bank 'calls
back', to verify that they are talking to the person expected). This is
rare in PC applications, but is quite common in some other OS's, but can
be used on the PC, so that the 'callback', is operating at a different
security level to the calling code. There is also the 'billing' reason (as
in the phone call, where you call somebody, and they say they will 'call
back', so that the charges go onto their account). In the computer
version, this allows the 'callback', to be using time from the subroutine
process, rather than from the main code. Again this could be at a
different priority to the calling routine.

Best Wishes



Re: what's a callback?

Quoted text here. Click to load it
Reentrant code means that a program can have more than one thread
executing concurrently.

http://vergil.chemistry.gatech.edu/resources/programming/threads.html

--
Best Regards,
Mike

Re: what's a callback?

Quoted text here. Click to load it


My illustrative example is a cooking school. One big recipe is posted
on the wall, and lots of students are reading it and cooking, each at
their own pace. They maintain their own local variables, the stuff in
their pots. The code remains pure as long as nobody splashes anything
on it.

John






Re: what's a callback?

Quoted text here. Click to load it

That's called static linking.

--
Best Regards,
Mike

Re: what's a callback?

Quoted text here. Click to load it

call

Not as I understand things.  Static linking is when you satisfy all
external references at compile/link time, incorporating all the library
routines right into your bound executable.  This generally makes for
quite large (megabytes) executable files, but also means that the
executable contains everything necessary to run.  This means people wont
have to install a bunch of libraries to be able to execute it.

This is as opposed to dynamic linking where external references are
satisfied at run-time.  This is done in windows with DLL libs or in
Linux with .so libs.  The executable file only contains references to
the desired routines and acceptable versions (aka stubs); a dynamic
linker pieces it all together just in the nick of time.  The dynamic
linker is part of the OS.  This tends to make the executables much
smaller as all that's in them is the core code of the application and a
bunch of external references (not to be confused with object files).

There is no mandate of recursion or re-entrancy other than that dynamic
library scenarios are typically done in a manner to support a single
resident copy of the code segment even with multiple threads
simultaneously executing.

Statically linked programs would usually lead to multiple copies of the
same code being in memory when multiple occurrences of the program are
in execution.  It's also possible that the OS might handle two
occurrences of the same executable by using one mostly shared copy by
implementing copy-on-write to clone pages as necessary.

I guess that's my 2cents anyhoo.  ;-)


Re: what's a callback?

Quoted text here. Click to load it

Yup. I'm still talking of static storage but thinking of linking.

<snip>
--
Best Regards,
Mike

Re: what's a callback?
Quoted text here. Click to load it

Example.
Take the Windows GDI LineDDA function. It takes 2 points as input and
calculates all points that make a line between them. Now LineDDA calculates
the first point, but it can't just return to the caller because the other
points have to be calculated too. OTOH, it doesn't know what to do with the
point (should it be drawn on a canvas, or added to a list?)
That's why the calling routine has to supply a pointer to a callback
function. Each time LineDDA has calculated a point it passes it to the
callback function. The callback function may draw the point on a canvas,
that's part of the application, and after it's done it returns control back
to the LineDDA function, which then goes on to calculate the next point.
So the application calls LineDDA, and during the LineDDA algorithm it calls
back an application function.
In the LineDDA case the callback will called several times, but it could
also be just once.

Another example.
Hans-Bernhard already mentioned sorting.
Sorting can only be done within ordered set. Numerical lists are ordered
differently from numerical lists, so you'll have different compare
functions. Apart from the comparison itself however, the sorting algorithm
can be the same for any type of set.
So you write a sort routine requiring a callback function. The sorting
routine knows when which item should be compared to which other. That's
defined in the algorithm. But it doesn't know how thsi comparison is to be
done. So it calls the callback, saying "hey, I've got an item A and an item
B here which require comparison. Which should go first?". The callback
function decides and returns the result to the sorting routine, which may
e.g. decide that A and B should be swapped.

HTH

--
Steven



Re: what's a callback?

Quoted text here. Click to load it

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.




Re: what's a callback?

Quoted text here. Click to load it

When you pass the address of a subroutine (usually in your code) to
something so that something can call the passed subroutine the subroutine
would often be called a callback.

Typically used for things like a list iterating routine where the callback
would be called for each item in the list.



Re: what's a callback?

Quoted text here. Click to load it
It's just windows hyperbola. Click a (say) button  somewhere and the ID
number you gave the button is stored on the "message" stack. At some point
in your prog' you may wish to rummage through the messages to see if that
particular number has turned up.
If you've a PowerBasic for windows, the help file makes a (bad!) effort to
describe it.
regards
john




Site Timeline