I want 500 objects to be processed concurrently using multithreading. These objects will have some initial data before the threads are created.

I am creating 5 threads and each thread takes 100 objects and starts the operation.

Here is the code.

public class InputData
{
   public string initialData {get; set;}
   public string formula {get; set;}
   public string resultData {get; set;}
}

public static List&lt;string&gt; result = new List&lt;string&gt;(500);

public static void Main()
{
    List&lt;InputData&gt; lst = new List&lt;InputData&gt;(500);

    List&lt;InputData&gt; lst_1 = .. // This will hold 1 to 100 objects
    List&lt;InputData&gt; lst_2 = .. // This will hold 101 to 200 objects
    List&lt;InputData&gt; lst_3 = .. // This will hold 201 to 300 objects
    List&lt;InputData&gt; lst_4 = .. // This will hold 301 to 400 objects
    List&lt;InputData&gt; lst_5 = .. // This will hold 401 to 500 objects

    Thread t1 = new Thread(Update);
    ...
    ...
    Thread t5 = new Thread(Update);

    t1.Start(lst_1);
    ...
    t5.Start(lst_5);

    //while condition to wait for the threads to finish processing
    while(...)
    {
        ..
    }
}

public static void Update(List&lt;InputData&gt; lstAll)
{
    lstAll.resultData = lstAll.initalData + lstAll.formula;

    //result.Add(lstAll.resultData); 
}


As you can see from the code, each thread uses a bunch of objects. And I am updating only the resultData property of each object. 

Is locking needed in this program? Can anyone please help

.net version is 3.5


Question: Solving a two point boundary problem for a piecewise system of equations
Answer: There is no need to use Piecewise because both $x(t)$ as well as $y(t)$ remain non negative.
Furthermore, the equation for x is independent of y and can be solved analytically.

The result $x(t)$ is then put into the equation for $y(t)$ which will be solved numerically.

Finally we verify our first statement about the non-negativity.

Ok, here we go.

The eqution for $x(t)$ is

sx = DSolve[x'[t] == x[t]^(3/4) - x[t] &amp;&amp; x[0] == 1, x[t], t]


We can safely ignore the error messages; they are just information which is not relevant here.

(* Out[105] = {{x[t] -&gt; E^-t (-2 + E^(t/4))^4}, {x[t] -&gt; E^-t ((-1 - I) + E^(t/4))^4}, {x[t] -&gt; E^-t ((-1 + I) + E^(t/4))^4}} *)


Taking the real-valued solution

xx[t_] = x[t] /. sx[[1]]

(* Out[106]= E^-t (-2 + E^(t/4))^4 *)

Plot[xx[t], {t, 0, 30}]




Now solving numerically the equation for $y(t)$ using the previously obtained function $xx(t)$:

sy = NDSolve[y'[t] == (1 - y[t])/xx[t]^(1/4) + y[t] &amp;&amp; y[0] == 10, y[t], {t, 0, 50}][[1]]


$\{y[t]\to \text{InterpolatingFunction}[\{\{0.,50.\}\},&lt;&gt;][t]\}$

Works out smoothly, no precision problems.
Here's the function itself

yy[t_] = y[t] /. sy


$\text{InterpolatingFunction}[\{\{0.,50.\}\},&lt;&gt;][t]$

Finally ploting both functions together, magnifying $x(t)$ by a factor of ten for better visibility:

Plot[{10 xx[t], yy[t]}, {t, 0, 30}, PlotRange -&gt; {-1, 20}, PlotLabel -&gt; "blue x(t), red y(t)"]




Nice problem. Hope this helps.

Regards,
Wolfgang