Re: [AD] timer_mutex again |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> Ah, cheers! Attached is a patch for dialog_message() instead, with a
> verbose explanation.
The only potential nasty side-effect I can think of is that dialog_message()
will acquire/release the screen for every object. But given that
scare_mouse() is also invoked for every object, that may go unnoticed in
practice.
> >I should have documented it in timer.c.
>
> Patch attached; what do you think?
First of all, thanks. :-)
However,
static void *timer_mutex = NULL; /* global timer mutex */
+ /* Why we need timer_mutex:
+ *
+ * 1. So _timer_queue[] is not changed in the middle of
+ * _handle_timer_tick's loop, possibly causing a null pointer
+ * dereference or corruption;
+ *
+ * 2. So that after "remove_int(my_callback);" returns, my_callback
+ * is guaranteed not to be in the _timer_queue and will not be
+ * called from the timer thread.
+ */
After remove_int(my_callback), my_callback is guaranteed not be in the timer
queue anymore (unless install_int, but that's #1). The problem is that
my_callback can have been fired but has not completed yet; context switch;
the main thread returns from remove_int and set my_pointer to 0; context
switch; the callback dereferences my_pointer. Ergo remove_int must wait for
all callbacks to have completed before returning.
--
Eric Botcazou