threads in browser javascript

D

dd

Whenever anyone asks me, I've always said there are no
threads in browser JavaScript. I heard Douglas Crockford
say it last week in his Yahoo lecture too. I've always been
not too worried about reentrancy and being threadsafe in
general.

Weirdly though, one day I was debugging in Visual Studio
and was halfway through a particular function that had been
called by some inline code or user click.

At a certain point while stepping through, some other event
(which had that same function assigned to it) resulted in a
threaded call to that same function. I then found myself
stepping through this event-triggered call right through to
the end. When I executed the final } I then found myself
returning back to my original position in that function, where
I was before the event.

So although there aren't parallel threads running, it appears
that script execution can be interrupted. It is therefore
important to make sure that a function that makes use of
globals would need to consider that at any time an event
may occur, and the handler function for that array would be
able to change those globals.

I think setInterval and setTimeout are not sufficiently privileged
to interrupt a script path. I suspect that the current function
chain/sequence would complete first before the set* gets a
look in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,815
Messages
2,569,702
Members
45,492
Latest member
juliuscaesar

Latest Threads

Top