Welcome Guest. Please Login or Register. Apr 1st, 2018, 03:30am
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. We apologize Conforums does not have any export functions to migrate data. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
Serialized callbacks
« Thread started 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.
Re: Serialized callbacks
« Reply #1 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
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.