Advertisement
Guest User

Untitled

a guest
May 1st, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.00 KB | None | 0 0
  1. module z;
  2.  
  3. import std.stdio;
  4. import std.concurrency;
  5. import core.thread;
  6. import std.variant;
  7.  
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9.  
  10.  
  11.    
  12. private struct Exit{};
  13. private struct supervisorAnswer {
  14. <------>Variant ret;
  15. }
  16.  
  17. private __gshared Tid supervisorTid;
  18.    
  19. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  20.  
  21. private void supervisor() {
  22.     static Variant[string] zval;
  23.     bool done = false;
  24.     void _store(T)(string k, T v) {
  25.         assert(k.length > 0);
  26.         zval[k] = v;
  27.     }
  28.  
  29.     void _get(Tid id, string k) {
  30.         id.send(supervisorAnswer(zval.get(k, Variant("ZBX_NOTSUPPORTED"))));
  31.     }
  32.  
  33.     while (!done) {
  34.         supervisorAnswer answer;
  35.         receive(
  36.             (Exit s) { done = true; },
  37.             &_store!long,
  38.             &_store!ulong,
  39.             &_store!int,
  40.             &_store!uint,
  41.             &_store!float,
  42.             &_store!double,
  43.             &_store!string,
  44.             &_store!Variant,
  45.             &_get,
  46.             (Variant e) {  writeln(e); },
  47.         );
  48.     }
  49. }
  50.  
  51. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52.  
  53.  
  54. Variant Get(const string s) {
  55.     Variant r;
  56.     supervisorTid.send(thisTid, s);
  57. writeln("TUQLUE");
  58.     receive(
  59.         (supervisorAnswer a) => r = a.ret
  60.     );
  61. writeln("42");
  62.     return r;
  63. }
  64.  
  65. void Set(T)(const string s, T v) {
  66.     supervisorTid.send(s, v);
  67. }
  68.  
  69. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70.  
  71. shared static this() {
  72.     supervisorTid = spawn(&supervisor);
  73. }
  74.  
  75. shared static ~this() {
  76.     send(supervisorTid, Exit());
  77. }
  78.  
  79. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80.  
  81. void main() {
  82.     Set("1", 11);
  83.     writeln(Get("1"));
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement