Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,I am new to boost threads and i have a char type for loop.Inside my for loop i am calling a function which does different operations based on the input char....below is my code

C++
char * letters = "ABCDEFGHIJKLMNOPQRSTUVWXZ";

  for (char * ptr = letters; *ptr != 0; ++ptr)
  {
    char ch = *ptr;
    str<< ch;
    ScaleData(str,Vector_node_double,ArrayIndex);
    ArrayIndex++;
    str.str("");
    str.clear();

  }


Inside ScaleData() function i compute some values and store them into an array..size of the array is 26 (it depends on the iterations of the for loop)..After finishing the for loop i got the biggest value from the array..My question is i want to to run for loop in different threads at the same time and store each computed value in the array..

ex :
C++
ScaleData(A,Vector_node_double,ArrayIndex); // thread one
ScaleData(B,Vector_node_double,ArrayIndex); // thread two
ScaleData(C,Vector_node_double,ArrayIndex); // thread three
ScaleData(D,Vector_node_double,ArrayIndex); // thread four
.
.
.


Need help guys... :-)
Posted
Updated 10-Sep-13 9:55am
v3

Use a barrier[^] - the 'trick' is that all the threads, including the thread that is supposed to do something when the other threads have finished, have to 'pass' the barrier.

Best regards
Espen Harlinn
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900