Multithread Help

Hi guys,

I am basing my work off of this example :
http://msdn.microsoft.com/en-us/library/kdzttdcb%28VS.71%29.aspx

Now, the only problem is, when I begin the thread I need to call a function that passes variables. I am super new to threads, I.E., this is it.

This is my code:
_beginthread( compileData(boardIndex, pBuffer, fpData1, fpData2, fpData3, fpData4), 0, NULL );

And I get the follow error:
error: invalid use of void expression

This is my function deceleration:
void compileData(U32 boardIndex, U16 *pBuffer, FILE *fpData1, FILE *fpData2, FILE *fpData3, FILE *fpData4)

Any idea how I can call this function and pass it the variables and have it run on a new thread?

It sais on that page you need a void func(void *) function... You have alot more...

You could do samenhing likje this:

1
2
3
4
5
6
typedef struct{
int Num;
char* pBuf;
}mystruct;

void* addem(mystruct* );
Last edited on
Good catch on what it told me I needed to have...!

As I said, I am new, and just kludging stuff together. So if I make my structure with all my variables, how do I pass all my variables to my function?

I
example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <windows.h>
#include <stdio.h>
#include <process.h>
#include <time.h>  

typedef struct 
{
	char A;
	char B;
}CHARS;

void loop( void* args )
{
	CHARS *chars = (CHARS*)args;
	while(1)
	{
		printf( "loop: %c %c\r\n" , chars->A, chars->B );
		Sleep(2000);
	} 
} 

int main()
{ 
	CHARS chars1 = { '1' , '2' };
	CHARS chars2 = { '3' , '4' };

	// Create the second thread.
	_beginthread( &loop, 0, &chars1 );

	while(1)
	{
		printf(  "main: %c %c\r\n" , chars2.A, chars2.B );
		Sleep(1000);
	} 

	return 0;
}
Last edited on
Thanks for all your help, you da man!

Last edited on
Topic archived. No new replies allowed.