Title: Synchronous Javascript JavascriptCSP C' Petitpierre, EPFL, Switzerland
1Synchronous Javascript( Javascript-CSP)C.
Petitpierre, EPFL, Switzerland
http//ltiwww.epfl.ch/sJavascript/SJSources/Plant.
html http//ltiwww.epfl.ch/sJavascript
2An example
Generator
Channel
when (ON) waituntil(now()2000) chan.put(x)
Consumer
when (parcel available) accept get
when (place available) accept put
when (ON) chan.get(x)
sinkStart.clicked() ON ! ON
startStop.clicked() ON ! ON
sinkStop
waituntil(now()1000)
startStop
3Synchronous Javascript
- Creates a concept close to the threads
- Synchronization inspired form CSP/CCS
- Merges the concepts of thread and object
- Runs on all browsers
4Source of the channel
process Channel(name) var fifo new
Array(0) this.put function(data)
fifo.push(data) this.get function(data)
return fifo.shift() this.run
function() for () select
case when (fifo.lengthgt0) accept
get case when (fifo.lengthlt6)
accept put showChannel(fifo.length
)
Interface Scheduling
5The (weird) trick to introduce pseudo-concurency
Scheduler
this.run function() for ()
switch(this.J_state) case 10000
this.J_init() // select statement if
((fifo.lengthgt0)) this.J_accept(10003
, this.JM_get) if
((fifo.lengthlt6)) this.J_accept(10004
, this.JM_put) if
(this.J_syncWait(17)) break
else return . . .
case 10003 . . . case 10004 .
. .
6Introduction of concurrency
this.run function() for ()
switch(this.J_state) case 10000 . .
. case 10003 this.J_state
10002 break case 10004
case 10002 showChannel(fifo.length)
this.J_state 10000
JUMP ( basis for any compiler )
7Kernel
- ready process list
- waiting process list
- list of processes waiting for synchronization
accept method1 method2 call
object3/method3 object4/method4
accept method3 call object4/method5
object1/method2
8Kernel
1
- scheduler
- syncWait
- syncWait
2
3
break (partner found) return (no
partner) kill (return, registered
in no list)
4
5
6
7
9Connection Listener-Synch Objects
- process Button(name)
- this.clicked function()
- this.data 0
- // no run method
- this.synchronize function(data)
- if (this.inSyncList)
- return
- this.data data
- accept clicked // non blocking
-