90 likes | 334 Views
Synchronous Javascript ( = Javascript-CSP) C. Petitpierre, EPFL, Switzerland. http://ltiwww.epfl.ch/sJavascript/SJSources/Plant.html http://ltiwww.epfl.ch/sJavascript. An example. Generator. Channel . when (ON) waituntil(now()+ 2 000) chan.put(x). Consumer.
E N D
Synchronous Javascript( = Javascript-CSP)C. Petitpierre, EPFL, Switzerland http://ltiwww.epfl.ch/sJavascript/SJSources/Plant.html http://ltiwww.epfl.ch/sJavascript
An 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
Synchronous Javascript Creates a concept close to the threads Synchronization inspired form CSP/CCS Merges the concepts of thread and object Runs on all browsers
Source 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.length>0) accept get case when (fifo.length<6) accept put } showChannel(fifo.length) } } } Interface Scheduling
The (weird) trick to introduce pseudo-concurency Scheduler this.run = function() { for (;;) { switch(this.$J_state) { case 10000: this.$J_init() // select statement if ((fifo.length>0)) { this.$J_accept(10003, this.$JM_get) } if ((fifo.length<6)) { this.$J_accept(10004, this.$JM_put) } if (this.$J_syncWait(17)) { break } else { return } . . . case 10003: . . . case 10004: . . . }}}
Introduction 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 )
Kernel • 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
Kernel 1 2 scheduler syncWait syncWait 3 break (partner found) return (no partner) kill (return, registered in no list) 4 5 6 7
Connection 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 } }