Help with boost::thread

Well, I have two functions:
1
2
3
4
5
6
7
8
9
10
11
12
13

void function_to_boost ( int a, int b )
{
// some code
}

void main ( )
{
    boost::thread thread ( boost::bind ( function_to_boost, 4, 5 ) );
    thread.join ( );

    // other code
}


I wan to know, how to make, that main function does not wait for 'function_to_boost' will be finished executing, and continue working with next code? I was made this thing with '_beginthread', but don't know how to make it with boost library.
thread.join() is waiting for the thread to finish. If you don't want to wait, don't call thread.join().
Thanks
Now it calls function in other thread and everything goes right, except that my function does not work correctly:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// begin thread
boost::thread	thread	( boost::bind ( _getfile, remote, local ) );
	//thread.join	();

static size_t my_fwrite	( void *buffer, size_t size, size_t nmemb, void *stream )
{
	CFTP::ftp_getfile 
		*out	= ( CFTP::ftp_getfile * ) stream;
  
	if	( out && !out -> fhandle ) 
	{
		/* open file for writing */ 
		fopen_s ( &out -> fhandle, out -> filename, "wb" );
		if	( !out -> fhandle )
			return -1; /* failure, can't open file to write */ 
	}
	return	fwrite ( buffer, size, nmemb, out -> fhandle );
}

void	_getfile	( const char *remote, const char *local )
{
	CFTP::ftp_getfile
		ftpfile	=
	{
		local,
		remote,
		NULL
	};

	CURL
		*h;
	CURLcode
		r;

	h	= curl_easy_init	( );

	if	( h != NULL )
	{
		char
			info	[ MAX_PATH + 100 ];

		sprintf_s	( info, "ftp://%s/%s", Ftp.ServerName, remote );

		curl_easy_setopt	( h, CURLOPT_URL, info );
	
		sprintf_s	( info, sizeof info, "%s:%s", Ftp.UserName, Ftp.Password );

		curl_easy_setopt	( h, CURLOPT_USERPWD, info );

		curl_easy_setopt	( h, CURLOPT_WRITEFUNCTION, my_fwrite );
		curl_easy_setopt	( h, CURLOPT_WRITEDATA, &ftpfile );
		curl_easy_setopt	( h, CURLOPT_VERBOSE, 1L );

		r	= curl_easy_perform	( h );
		curl_easy_cleanup	( h );logprintf ( " nu mldc turi but" );

		if	( ftpfile.fhandle )
			fclose	( ftpfile.fhandle );

		if	( !r )
		{
			
		}
	}
}


If I use thread.join, everything works fine, but when I don't use it - it fails. cURL gives an error

1
2
3
4
5
6
7
* Failed writing body (4294967295 != 550)
* Remembering we are in dir ""
< 226 Transfer OK
> QUIT
< 221 Goodbye
* Closing connection #0
* Failed writing received data to disk/application


It looks like void *stream, passed to my_fwrite function is empty.
Last edited on
I guess it is because you should call thread.join() just before main() ends. The thread might not even started when main() ended
I have checked everything, thread starts and ends, but it not pas arguments throught my_fwrite function, but if i use thread.join, argumens are passed correctly
Topic archived. No new replies allowed.