Some questios about AfxBeginThread

hi everybody, i still have problems with parallel programming.
i want to solve little problem, where i have matrix 2x2 and vector consisting of 2 elements and i must multiply them using parallel programming. result will be some vector.
i want to solve this like this:
1st element will be calculated in 1 process(thread) and the second element in second process(thread) at one time. i want to do this using AfxBeginThread, but have some problems with passing arguments, here it is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
UINT ThreadMultiply(LPVOID lp)
{
	CString s;
	int * pi = (int *) lp;
	
	for(int i = 1; i < (*pi); i++)
	{
		s.Format( "%d", (*(pi+i)) );
		AfxMessageBox(s);
	}

	return 1;
}



void CProgramm::OnBnClickedButton15()
{
	int count[6] = {5,1,2,3,4,5};
	AfxBeginThread(ThreadMultiply,count,NULL);
}


i get 1, except 1 2 3 4 5

my questions:
why it happens?
is my logic right, or i don't understand what is parallel programming?
what is difference between thread and process(i already read wiki)?

thanks for answers and sorry for my english))!
Last edited on
I tried this and it works the way I expected it to work.
I get a separate messagebox and each box has a single number in it.
So the first box has number 1 - you press OK and the next message box diplays with the number 2, .. and so on.
NOTE - You will NOT get just one messagebox with 1 2 3 4 5 written it it. This is because each time
the Format function is called, the previous content of the CString is overwritten.

Note that in your example the for loop should be like this
for(int i = 1; i <= (*pi); i++) NOT for(int i = 1; i < (*pi); i++)
You will NOT get just one messagebox with 1 2 3 4 5 written it it. This is because each time
the Format function is called, the previous content of the CString is overwritten.

i know it,
my questions is
is my logic right, or i don't understand what is parallel programming?
what is difference between thread and process(i already read wiki)?
Topic archived. No new replies allowed.