[Mono-dev] Problem with EventWaitHandle.WaitOne(timeout) during setting time
Mirko Wischer
Mirko.Wischer at sma.de
Tue Jan 17 11:58:44 UTC 2012
Hi everyone,
we hit a problem concerning EventWaitHandle.WaitOne(timeout) in conjunction with
changing system time during long timeouts.
The problem only exists using named events. After a short analysis I think I found the main problem:
In the io-layer the WaitForSingleObjectEx method uses _wapi_calc_timeout (from misc.c) to compute
an absolute time from the given timeout, but the absolute timeout is computed using "gettimeofday".
That will cause problems if the system clock changes during checking (named events spin through fake timeouts
until the absolute timeout seems to be reached).
Unnamed events also use the _wapi_calc_timeout method to compute the absolute timeout. This timeout is
then used in mono_cond_timedwait (but this only wraps "normal" pthread conditions).
So I prepared a patch (see attached files) using clock_gettime(CLOCK_MONOTONIC,..) instead of gettimeofday, but this also requires
a change for unnamed events, because the pthreads condition needs to know what kind of clock provides the
absolute timeout.
This seems to fix the issue for us. Is this an appropriate way to fix this? What do you think.
_wapi_calc_timeout is also used in some other timeout relevant functions, but I just found
the "faketimeout" way of checking the absolute timeout and the mono_cond_timed_wait.
Or do I miss some occurrences/cases checking the absolute timeout.
Thanks for looking at this.
CU Mirko
___________________________________________________
SMA Solar Technology AG
Aufsichtsrat: Guenther Cramer (Vorsitzender)
Vorstand: Juergen Dolle, Roland Grebe, Pierre-Pascal Urbon, Marko Werner
Handelsregister: Amtsgericht Kassel HRB 3972
Sitz der Gesellschaft: 34266 Niestetal
USt-ID-Nr. DE 113 08 59 54
WEEE-Reg.-Nr. DE 95881150
___________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120117/455f14c9/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EventHandle_WaitOne.patch
Type: application/octet-stream
Size: 902 bytes
Desc: EventHandle_WaitOne.patch
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120117/455f14c9/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EventHandle_WaitOne2.patch
Type: application/octet-stream
Size: 473 bytes
Desc: EventHandle_WaitOne2.patch
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120117/455f14c9/attachment-0001.obj>
More information about the Mono-devel-list
mailing list