LB Booster
Programming >> Compatibility with LB4 >> Serialized callbacks http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1480277053 Serialized callbacks
Post by Richard Russell on Nov 27th, 2016, 7:04pm
Comparing how LB4 and LBB behave in respect of callbacks, it looks as though LB4 has some mechanism to 'serialize' them. That is, if callbacks arrive more quickly than they can be processed it seems that a new callback will not be processed until the previous one has completed. Put another way, there appears to be a mechanism to prevent the callback function being called re-entrantly.
LBB has no such mechanism. If a second callback happens before the first one has completed, it will pre-emptively interrupt the callback function. Often this won't matter: because of the way variables are 'local' to the function the second call won't cause the 'pre-empted' function to misbehave.
However there may be a problem if the callback function performs operations that must happen sequentially; in that case you could get a situation in which the 'second' callback performs the operation 'before' the first callback does! There's no practical way I can think of that LBB's callbacks could be serialized so do be aware of this issue, albeit that it should rarely be a problem in practice.
Richard.
Re: Serialized callbacks
Post by RobM on Nov 28th, 2016, 01:24am
I'm pretty certain I haven't had any issues arise from this, though I don't have very many callbacks in my program. Over the past 2 years they have probably been called a few trillion times
Re: Serialized callbacks
Post by Richard Russell on Nov 28th, 2016, 10:56am
I'm pretty certain I haven't had any issues arise from this, though I don't have very many callbacks in my program. Over the past 2 years they have probably been called a few trillion times
Callbacks in other languages, like C, typically won't be serialized so LBB is working 'conventionally', which is why I would not generally expect there to be a problem.
The particular program which alerted me to this issue is 'Liberty 8' which was recently posted at the LB Community Forum; this is an interpreter for the CHIP-8 virtual games machine. In this program Windows Timer Callbacks are used to control various aspects of the virtual machine, including instruction fetches; obviously these must happen in the correct sequence!
Fortunately in this particular case the problem can be easily circumvented by incorporating a semaphore which causes 'early' callbacks to be discarded.