|
-
April 4th, 2013, 02:43 AM
#11
Re: Can local variable be passed as parameter into a new thread?
D Drmmr, that code doesn't seem correct to me because std::thread destructor will call terminate() if still joinable ( due to exception safety reasons ). Hence, you must either detach() or join() in some_function().
note that boost::thread had a different behavior as it automatically detached itself during destruction. Newest versions conforms to the std behavior though ( don't recall the exact version ... ).
BTW, one can use a lambda with by-value capture in place of std::bind ( more readable IMHO, and you can gain one less allocation and no virtual call ) or even just write "std::thread( ProcessContentThreadFunction, strFileName );" ( everything is copyed in the calling thread and the thread ctor syncs with the ProcessContentThreadFunction call; that said, I cannot recall from which VC++ version this is actually supported ... ) or use std::async ( but you need to take care of the future<> in this case, otherwise the caller will block as in std::thread(...).join() ).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|