Hi, I made a small program which sorts a Vector of 100000 ints. I use a quicksort , not the recursive one. With the single thread version I takes about 22s to complete. -now the problem and the question: I have written a second version which 1. first make a partitioning 2. start an independent thread on eatch subpartition = 2Threads So the sorting continues on 2 separate threads with no locks or anythig to block; I got almost the same time when running. Why happens to run in same interval of time. Will Windows7 be very smart to optimize the code to run on multiple cores even if it is a single thread? I have a x6 Cpu. here is the sample code (test code)
class VectorSafeConcurency
{
int[] V;
const int sizeV = 100000;
//Stack numbers = new Stack();
void push2(Stack s, int a, int b)
{
s.Push(b);
s.Push(a);
}
public VectorSafeConcurency()
{
V= new int\[sizeV\];
int value= sizeV;
for (int i = 0; i < sizeV; ++i)
V\[i\] = value--;
}
void exchange(ref int x, ref int y)
{
int temp= x;
x= y;
y= temp;
}
int partition(int\[\] A, int l, int r)
{
int i = l - 1;
int j = r;
int v= A\[r\];
for(;;)
{
while(A\[++i\] \= j) break;
exchange(ref A\[i\], ref A\[j\]);
}
exchange(ref A\[i\], ref A\[r\]);
return i;
}
struct ThData
{
public int\[\] A;
public int l;
public int r;
public ThData(int \[\]a, int i, int j)
{
A = a; l = i; r = j;
}
}
void thWorkerParititoner(object data)
{
int\[\] A = ((ThData)data).A;
int l = ((ThData)data).l;
int r = ((ThData)data).r;
quicksort(A, l, r);
}
void StartQuicksort(int\[\] A, int l, int r)
{
if (r <= l) return;
int i = partition(A, l, r);
Thread t1 = new Thread(thWorkerParititoner);
t1.Start(new ThData (A, l, i-1));
Thread t2 = new Thread(thWorkerParititoner);
t2.Start(new ThData(