- From: Keean Schupke <keean@fry-it.com>
- Date: Fri, 7 Jan 2011 00:17:18 +0000
- To: Jonas Sicking <jonas@sicking.cc>
- Cc: Joćo Eiras <joao.eiras@gmail.com>, public-webapps WG <public-webapps@w3.org>
- Message-ID: <AANLkTinP2W0yDgUnCLQ-YFqu5HPjHHr8o94W9iAYZrfX@mail.gmail.com>
Applying this to JavaScript (ignoring local storage and just implementing an STM) would come up with something like: 1) Objects from one thread should not be visible to another. Global variable "test" defined in the UI or any worker thread should no be in scope in any other worker-thread. 2) shared objects could be accessed only though the "atomic" method (implemented natively). atomic(function(shared) { shared.x += 1; shared.y -= 2; }); Here, the callback is the transaction, and "shared" is the shared namespace... Thats all you need for a basic implementation. The clever stuff is all hidden from the user. We could implement "retry" by returning true... the guard could just be a boolean function too: atomic(function(shared) { if (queueSize > 0) { // remove item from queue and use it return false; // no retry } else { return true; // retry } }); Thats pretty much the entire user visible API that would be needed. Of course the implementation behind the scenes is more complex. Cheers, Keean. 2011/1/6 Keean Schupke <keean@fry-it.com> > Here's a link to some papers on STM: > > http://research.microsoft.com/en-us/um/people/simonpj/papers/stm/ > > A simple example: > > http://www.haskell.org/haskellwiki/Simple_STM_example > > Here's a tutorial: > > http://book.realworldhaskell.org/read/software-transactional-memory.html > > Here's a link to the docs: > > http://hackage.haskell.org/package/stm > > > Cheers, > Keean. > > > 2011/1/6 Keean Schupke <keean@fry-it.com> > >> Did you see section 7 in the link I posted? >> >> 7 Implementations >> 7.1 C/C++ >> 7.2 C# >> 7.3 Common Lisp >> 7.4 Haskell >> 7.5 Java >> 7.6 OCaml >> 7.7 Perl >> 7.8 Python >> 7.9 Scala >> 7.10 Smalltalk >> >> JavaScript as a functional language (first class functions, closures, >> anonymous functions) has a lot in common with Haskell and other functional >> languages (Lisp)... Although as you can see there are plenty of OO >> implementations too. >> >> >> Cheers, >> Keean. >> >> >> 2011/1/6 Jonas Sicking <jonas@sicking.cc> >> >> 2011/1/6 Keean Schupke <keean@fry-it.com>: >>> > There is always Software Transactional Memory that provides a safe >>> model for >>> > memory shared between threads. >>> > http://en.wikipedia.org/wiki/Software_transactional_memory >>> > This has been used very successfully in Haskell for overcoming >>> threading / >>> > state issues. Combined with Haskells Channels (message queues) it >>> provides >>> > for very elegant multi-threading. >>> >>> Can you provide a link to the Haskell API which you think has been >>> working well for haskell. Or even better, considering that haskell is >>> a vastly different language from javascript, could you propose a >>> javascript API based on Software Transactional Memory. >>> >>> / Jonas >>> >> >> >
Received on Friday, 7 January 2011 00:18:40 UTC