Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. private void RunPoolThreads(int count, ThreadAction action)
  2. {
  3. // TODO: Run 'count' pool threads and execute 'action' in every one with appropriate range of data
  4. // TODO: Use 'ManualResetEvent' to synchronize operations
  5.  
  6. int step = _data.Length / count;
  7. var x = 0;
  8. for (int i = 0; i < count ; i++)
  9. {
  10. var start = x;
  11. var stop = x + step;
  12. x += step;
  13. if (i == count - 1)
  14. {
  15. stop = _data.Length;
  16. }
  17. ThreadPool.QueueUserWorkItem( o => action(start, stop));
  18.  
  19. manualResetEvent.WaitOne();
  20. manualResetEvent.Reset();
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement