Advertisement
snake5

SGScript - parallel processing | v0.5

Jun 2nd, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////// PARALLEL PROCESSING //////////////////
  2. include_shared( "sgspproc" );
  3.  
  4.  
  5. PPROC = pproc_create();
  6.  
  7.  
  8. /*
  9.     STRING
  10. */
  11.  
  12. job = PPROC.add_job( "
  13.  
  14. text = _T.get( 'text' );
  15.  
  16. for( i = 0; i < 10; ++i )
  17. {
  18.     print( text );
  19.     sleep( 20 );
  20. }
  21.  
  22. _T.set( 'info', { error = 5, wat = 'really?' } );
  23.  
  24. " );
  25.  
  26. job.set( "text", "thread   T W O\n" );
  27. job.start();
  28. for( i = 0; i < 10; ++i )
  29. {
  30.     print( 'thread  O N E\n' );
  31.     sleep( 20 );
  32. }
  33. job.wait();
  34. printvar( job.get( 'info' ) );
  35.  
  36.  
  37. /*
  38.     FUNCTION
  39. */
  40.  
  41. function threadproc()
  42. {
  43.     text = _T.get( 'text' );
  44.  
  45.     for( i = 0; i < 10; ++i )
  46.     {
  47.         print( text );
  48.         sleep( 20 );
  49.     }
  50.  
  51.     _T.set( 'info', { error = 5, wat = 'really?' } );
  52. }
  53.  
  54. job = PPROC.add_job( threadproc );
  55.  
  56. job.set( "text", "thread   T W O\n" );
  57. job.start();
  58. for( i = 0; i < 10; ++i )
  59. {
  60.     print( 'thread  O N E\n' );
  61.     sleep( 20 );
  62. }
  63. job.wait();
  64. printvar( job.get( 'info' ) );
  65.  
  66. ///////////////////// OUTPUT ////////////////////////////
  67. SGSVM [SGScript v0.8.2]
  68. thread  O N E
  69. thread   T W O
  70. thread  O N E
  71. thread   T W O
  72. thread   T W O
  73. thread  O N E
  74. thread  O N E
  75. thread   T W O
  76. thread   T W O
  77. thread  O N E
  78. thread  O N E
  79. thread   T W O
  80. thread   T W O
  81. thread  O N E
  82. thread  O N E
  83. thread   T W O
  84. thread  O N E
  85. thread   T W O
  86. thread  O N E
  87. thread   T W O
  88. object (0064B9B8) [1] dict
  89. {
  90.   error = int (5)
  91.   wat = string [7] "really?"
  92. }
  93. thread  O N E
  94. thread   T W O
  95. thread   T W O
  96. thread  O N E
  97. thread  O N E
  98. thread   T W O
  99. thread   T W O
  100. thread  O N E
  101. thread   T W O
  102. thread  O N E
  103. thread  O N E
  104. thread   T W O
  105. thread  O N E
  106. thread   T W O
  107. thread  O N E
  108. thread   T W O
  109. thread  O N E
  110. thread   T W O
  111. thread  O N E
  112. thread   T W O
  113. object (0064B958) [1] dict
  114. {
  115.   error = int (5)
  116.   wat = string [7] "really?"
  117. }
  118.  
  119. /////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement