Subj : Re: Threading in JavaScript To : comp.lang.javascript,netscape.public.mozilla.jseng From : "Laurent Bugnion, GalaSoft" Date : Sat Feb 01 2003 02:44 pm Hi, Gordan wrote: > Hi! > > I am aguessing that I am probably expecting WAY too much from JavaScript > implementations here, but I'll ask anyway... ;-) > > Is there any way to achieve _actual_ threading in JS? I know that in theory, > > setTimeout("myFunction(myParams)", Timeout); > > SHOULD fork a new thread to execute myFunction(myParams), but I have found > that it doesn't happen quite like that. On both IE6 and Mozilla 1.2.1 the > execution is SCHEDULED for NO LESS than Timeout miliseconds in the future. > This, however, doesn't GUARANTEE when the execution will begin. > > What happens instead is that all setTimeout() started functions are > scheduled in the future and execute sequentially, one after another. They > do not interleave their execution. > > I know that implementing safe threading is difficult, and that it opens a > whole new can of worms as far as variable locking/sharing is concerned, but > is such a feature present in ANY DOM compliant browser today? Is it even > planned in ANY of the browsers? I would really like to avoid the path of > Java applets and ActiveX controls if at all possible. > > TIA. > > Gordan Multithreading (with all features allowing for safe threading, resource locking, etc...) is available in many browsers: It's called Java applets ;-) In fact, it's one of the cases where I would recommend using an applet over a scripting solution. JavaScript doesn't offer multithreading inherently. But since you can control an applet using JavaScript (in LiveConnect enabled browsers), you can do what you want. For LiveConnect matters: http://www.galasoft-LB.ch/myjavascript/consulting/LiveConnect102 Laurent -- Laurent Bugnion, GalaSoft Webdesign, Java, JavaScript: http://www.galasoft-LB.ch Private/Malaysia: http://mypage.bluewin.ch/lbugnion Support children in Calcutta: http://www.calcutta-espoir.ch .