Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nsITimer thread safety

58 views
Skip to first unread message

Jason Duell

unread,
Jul 19, 2012, 4:04:12 PM7/19/12
to dev-platform
nsITimer.idl says nothing about thread safety. (Can we add some?)

From a glance at the code, it appears that it's safe to Cancel and
null-out an nsITimer from any given thread, so long as the timer
callback that's pointed to has thread-safe refcounting. Correct?

Jason

Boris Zbarsky

unread,
Jul 19, 2012, 4:16:17 PM7/19/12
to
If I recall correctly, it's "unsafe" to fire an nsITimer on any thread
other than the main thread. At least insofar as it will cause races on
the timers' delay adjustment mechanism.... It won't crash, but can
cause timer firing times to get all weird.

(Note that it's not _intended_ that this be unsafe; it's just
implemented in an unsafe way.)

-Boris

Jason Duell

unread,
Jul 19, 2012, 4:22:51 PM7/19/12
to dev-pl...@lists.mozilla.org
Right--but whether can we *cancel* timers from any thread is my specific
question here. Looks like you can if your callback is thread-safe IIUTCC

Jason

Henri Sivonen

unread,
Jul 20, 2012, 2:20:35 AM7/20/12
to dev-platform
On Thu, Jul 19, 2012 at 11:04 PM, Jason Duell <jdu...@mozilla.com> wrote:
> From a glance at the code, it appears that it's safe to Cancel and null-out
> an nsITimer from any given thread, so long as the timer callback that's
> pointed to has thread-safe refcounting. Correct?

At least the HTML parser relies on it being safe to call Cancel on a
thread that doesn't own the timer. (And the decision to rely on that
was based on investigating the timer code.)

--
Henri Sivonen
hsiv...@iki.fi
http://hsivonen.iki.fi/
0 new messages