1 / 15

Polyphonic JR

Polyphonic JR. Ludwik Ejsmont www.mdstud.chalmers.se/~ludwik/. Polyphonic C# - overview. Asynchronous Methods async postEvent(EventInfo data) { // large method body } Chords public class Buffer { public string Get() & public async Put(string s) { return s; } }.

sandro
Download Presentation

Polyphonic JR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Polyphonic JR Ludwik Ejsmont www.mdstud.chalmers.se/~ludwik/

  2. Polyphonic C# - overview • Asynchronous Methods async postEvent(EventInfo data) { // large method body } • Chords public class Buffer { public string Get() & public async Put(string s) { return s; } }

  3. JR - overview • Semaphores

  4. Transformation - Single synchronous method in a chord // Polyphonic version ... f(); ... public void f(..){ //body } // JR version public op void f(..); //declaration not necessary ... call f(); // ‘call’ keyword not necessary ... public void f(..){ // if without declaration we have //body add ‘op’ to definition header }

  5. Transformation- Single asynchronous method in a chord // Polyphonic version ... f(); ... public async f(..){ //body } // JR version public op void f(..); //declaration not necessary ... send f(); // ‘send’ keyword necessary ... public void f(..){ // if without declaration we have //body add ‘op’ to definition header }

  6. Transformation- No the same method used more than once in different chord headers public class Test1 { public async sendTest1(string st1); public async sendTest2(string st2); public string getTest() & sendTest1(string st1) & sendTest2(string st2) { return st1 + st2;} public static void Main() { Test1 test = new Test1(); test.sendTest1("Hello "); test.sendTest2("World "); Console.Write(test.getTest()); } } public class Test1 { public op void sendTest1(String); public op void sendTest2(String); public op String getTest() { String st1, st2; receive sendTest2(st2); receive sendTest1(st1); return st1 + st2 ;} public static void main(String [] args){ Test1 test = new Test1(); send test.sendTest1("Hello "); send test.sendTest2("World "); System.out.println(test.getTest()); } }

  7. Transformation - One synchronous, one asynchronous methods, possibly the same in different chord headers class Room { public Room (int size) { hasspaces(size); } private async hasspaces(int n); public void enter() & hasspaces(int n) { if (n > 1) hasspaces(n-1); else isfull(); } private async isfull(); public void leave() & hasspaces(int n) { hasspaces(n+1); } & isfull() { hasspaces(1); } } class Room { public Room (int size) { send hasspaces(size); } private op void hasspaces(int n); public void enter() { int n; receive hasspaces(n); if (n > 1) send hasspaces(n-1); else send isfull(); } private op void isfull(); public void leave(){ inni void hasspaces(int n){sendhasspaces(n+1);} [] void isfull(){send hasspaces(1);} } }

  8. Transformation - One synchronous, an arbitrary number of asynchronous methods, possibly the same in different chord headers class santa { ... static void waittobewoken() & elvesready() & reindeernotready() { reindeernotready(); … } & reindeerready() { … reindeernotready(); … } ... static void clearreindeernotready() & reindeernotready() { elvesready(); reindeernotready(); } }

  9. Transformation - One synchronous, an arbitrary number of asynchronous methods, possibly the same in different chord headers class ElvesReady {} class ReindeerNotReady{} public class Santa { private static ArrayList er = new ArrayList(); private static ArrayList rnr = new ArrayList(); private static sem mutex = 1; private static void waitToBeWoken() { while(true) { inni void elvesReady() { P(mutex); if (rnr.isEmpty()) { er.add(new ElvesReady()); V(mutex); } else { rnr.remove(0); V(mutex); send reindeerNotReady(); break; } }[] void reindeerNotReady() { P(mutex); if (er.isEmpty()) { rnr.add(new ReindeerNotReady()); V(mutex); } else { er.remove(0); V(mutex); send reindeerNotReady(); break; } } [] void reindeerReady() { send reindeerNotReady(); send reinWaiting(0); delay(); unharness.acceptn(9,"all …"); rcount++; break; } } } private static void clearReindeerNotReady() { P(mutex); if (!rnr.isEmpty()) { rnr.remove(0); V(mutex); } else { V(mutex); receive reindeerNotReady(); } }

  10. Transformation - Only asynchronous messages (more than one) in a chord public class Test3 { public op void m1(); public op void m2(); public op void m3(); String s = "Hello World"; public void m1(){ receive m2(); receive m3(); System.out.println(s); } public static void main(String [] args) { Test3 t3 = new Test3(); send t3.m1(); send t3.m2(); send t3.m3(); } } class Test3{ public async m1(); public async m2(); public async m3(); string s = "I am Test3"; when m1() & m2() & m3() { Console.WriteLine(s); } public static void Main() { T t3 = new Test3(); t3.m1(); t3.m2(); t3.m3(); } }

  11. Other issues • Inheritance • Exception handling • Problems with JR

  12. Conclusions • JR – more extensive, more familiar • Polyphonic C# - a different approach but treated more seriously • Transformation JR – Polyphonic C# seems much harder • Why no popular programming language treats concurrency seriously ?

  13. Sources • http://research.microsoft.com/~nick/polyphony/ • http://research.microsoft.com/comega/ • http://www.cs.ucdavis.edu/~olsson/research/jr/ • R. A. Ollson, A. W. Keen, “The JR Programming Language”, Kulwer Academic Publishers 2004 • www.mdstud.chalmers.se/~ludwik/polyphonicjr.html

  14. Questions ?

  15. Thank You!!

More Related