473,698 Members | 2,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which thread executes javascript code?

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("onT imeout()", 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
1 2689
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("onT imeout()", 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6626
by: Grandma Wilkerson | last post by:
My question concerns the documentation for Control.BeginInvoke(). At one point is says: "Executes the specified delegate asynchronously with the specified arguments, on the thread that the control's underlying handle was created on." later in that same documentation page it says... "Note The BeginInvoke method calls the specified delegate back on a
10
3173
by: Manny | last post by:
I have a web form "Page1.asp" and it reads data from a database, does some calculations, and displays the records in pages. Works fine. I have a button that displays on the page, defined as <input type="button" onClick="OutputData()"> The OutputData() function is a javascript function that simply does this: window.location = "Page1.asp?Flag=1";
14
5350
by: Daisy | last post by:
From this page: http://www.c-sharpcorner.com/2/mt_beginner1.asp Thread class's Abort method is called to kill a thread permanently. Make sure you call IsAlive before Abort. if ( thread.IsAlive ) { thread.Abort(); }
7
439
by: Ivan | last post by:
Hi there My work on threads continues with more or less success. Here is what I'm trying to do: Class JobAgent is incharged for some tasks and when it's called it starts thread which performs the job. Application contains one list of agents that are idle at the moment and list of busy agents. In loop it checks if there are agents in idle list and if there are some, it starts them.
1
2019
by: Jon | last post by:
My question is: Can the Garbage Collector (GC) suspended a managed thread while it is executing native code. The reason I am interested in this is that I have: 1) a native thread (N) that only executes native code, 2) a managed thread (M) that sometimes executes native code, 3) a critical section, that is shared by the native code portions of N & M. And I what to know: Can N be suspend by the GC? This would be true if the GC could...
4
1603
by: Larry | last post by:
On the following page: http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0407zhang/index.html IBM discusses a surrogate key generation function, along with a listing in Java (Appendix A at the end of the web page). However it seems the function is not thread-safe! Suppose for a certain Table X, the SURROGATEKEYVALUE is currently set to 100, and INCREMENT is set to 1. If 2 threads, A and B, enter
3
11036
by: Jamie Risk | last post by:
What thread does the DataReceived event run on? I'm preparing a design that uses the DataReceived event to stimulate a protocol state machine (PSM). The ambition is to have the serial process happen in the background, and when certain conditions are met, the PSM then triggers an event (myPacketIsHere for instance). The PSM will only ever deal with the serial data sequentially, i.e. through the use of locks and such, only one instance...
18
10226
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do with weirdness going on with the server I am talking to. Anyhow, this locked up state happens once in a while (maybe once per day) and I can't figure out how to deal with the locked up thread. If I issue a Thread.Abort() the exception never...
8
3433
by: Anthony Williams | last post by:
You need compiler barriers (_ReadWriteBarrier() in MSVC) to ensure things don't get rearranged across your atomic access functions. There's no need to drop to assembler either: you're not doing anything more complicated than a simple MOV. Anyway, if I was writing this (and I wouldn't be, because I really dislike singletons), I'd just use boost::call_once. It doesn't use a lock unless it has to and is portable across pthreads and win32...
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.