Multithreading problem.

I have problems with multithreading. When I do like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
boost::thread	thread	( boost::bind ( _getfile, remote, local ) );
thread.join	(); 

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


Everything goes right. But when I remove thread.join ( because I don't need to wait ), then I got strange symbols when I output 'local' and 'remote' params in function '_getfile'. Whats wrong with it?
Does the context of the boost::thread object resemble this?
1
2
3
4
5
6
7
{
    std::string string_a,string_b;
    const char *remote,*local;
    remote=string_a.c_str();
    local=string_b.c_str();
    boost::thread thread( boost::bind ( _getfile, remote, local ) );
}
If it does, the problem is that the lifetime of the pointer returned by std::string::c_str() is bound to the lifetime of the std::string object. Since you don't join, the std::strings are free to go out of scope while _getfile() is still running.
The easiest solution is to just pass copies of the strings and let the callee take ownership of them.
Thanks for answer, but can you give me an example of solution, because I don't know how
Up
Topic archived. No new replies allowed.