[Company Logo Image]    

Home Feedback Contents Search

4.4 Socket
4.1 Structure 4.2 Compiling 4.3 Example 4.4 Socket 4.5 OOP 4.6 Competing 4.7 Optimization 4.8 Connector 4.9 Merging 4.10 Emulation 4.11 Ordered Calls 4.12 Last-Only 4.13 Group Inputs 4.14 Complex Sys. 4.15 Prior Art... 4.16 Redundant SW 4.17 Visual SW 

Back Home Up Next

4.4 Construct for Interfacing with Legacy Code

The previously shown example of concurrently adding two arrays used an “all_done” function-call to report that the entire array has been added. In a project written entirely in spirit of stress-flow, the “all_done” function could simply be a call to another stress atom that would now use the result for something, call more atoms, which could eventually call our “add_arrays” again. However, recognizing the need to supply tools to easy coexist with code written previously, stress-flow included a “socket” construct to make it possible.

A socket construct is a special case of stress-flow atom that is not defined as a separate function but rather inside another function or another stress-flow atom. Other than that, it has all elements of regular stress-flow atom (an associated lock, stressed and relaxed sections, etc). Therefore, a socket is intended to be declared together with other regular atoms inside a “detach” or other stress-flow block. If a socket has a return value, this value gets returned to the caller through stressed/relaxed section separating return instruction.

const int n=100

some_type A[n],B[n],C[n];

//----------------------------------------------------

detach socket void all_done();

//----------------------------------------------------

detach

{  int total_count;

   void done_item()

   {  ++total_count;

      if ( total_count==n )

         all_done();

      return;

   };

   void zero_count()

   {  total_count=0;

   }; 

};

//----------------------------------------------------

detach void add_item(int i)

{  return;

   C[i] = A[i]+B[i]; //Time consuming operation     

   done_item();

};

//----------------------------------------------------

detach void add_arrays()

zero_count();

   for ( int i=0; i<n; i++ )

      add_item(i);

   void all_done()

   {

   };

};

FIG. 4: An example of “socket” construct use

Modified example of concurrent addition of arrays using socket construct is shown on FIG 4. Socket “all_done” is declared ahead of its use in atom “done_item,” and is declared inside “add_arrays” function. Once add_arrays finishes its loop of scheduling n of “add_item” atoms, it gets suspended waiting for “all_done” to be triggered. This happens when all finalized add_items report which triggers call to “all_done.” Routine “add_arrays” now resumes and returns to its caller, with all the results correctly calculated and stored. Thanks to “socket” construct, add_arrays could now be called from regular (non stress-flow) code just as if an ordinary non-parallel routine. Simple fact that add_arrays was declared as stress-atom itself with stressed section only guarantees that no new call to add_arrays will start before the previous one returns.

Back Home Up Next
Send mail to info@stressflow.com with questions or comments.
Copyright © 2005-2010. All Rights Reserved. Patents Pending in Multiple Jurisdictions.
First published 03/29/06. Last modified: 06/25/10