By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

Which thread executes javascript code?

P: n/a
Hi,

I am wandering whether all javascript code in one page is executed in
one thread. I know that javascript has no threading mechansim. No way
to tell which thread is running by code iteself.

For below code
<html>
<head>
</head>
<body>
<script type="text/javascript">
function onTimeout()
{
alert("time out");
}

setTimeout("onTimeout()", 5000);

while (true)
{
}
</script>
</body>
</html>
If there is only one thread and event loop, I suppose the script will
end in dead loop. But, in IE, the alert pops up after 5 seconds. How to
explain it?

Does each browser page has only one thread interpreting script?

Thanks,

Jul 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
mo************@gmail.com wrote:
I am wandering whether all javascript code in one page is
executed in one thread.
Javascript is not multithreaded.
I know that javascript has no threading mechansim. No way
to tell which thread is running by code iteself.
Where there are no threads there is no need to know "which thread is
running".
For below code
<html>
<head>
</head>
<body>
<script type="text/javascript">
function onTimeout()
{
alert("time out");
}

setTimeout("onTimeout()", 5000);

while (true)
{
}
</script>
</body>
</html>
If there is only one thread and event loop, I suppose the script will
end in dead loop.
Or when IE puts up the 'a script on this page is causing IE to run
slowly" dialog and offers the user an opportunity to abort it.
But, in IE, the alert pops up after 5 seconds.
No it does not. I suppose that if an IE version was set up to
automatically abort scripts that make it run slowly rather than putting
up the dialog then you may see that.
How to explain it?
Poor observations leading to false deductions.
Does each browser page has only one thread interpreting script?
Javascript is not multithreaded.

Richard.

Jul 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.