CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Threaded View

  1. #7
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Can local variable be passed as parameter into a new thread?

    Quote Originally Posted by forester View Post
    Can local variable be passed as the parameter for a new created thread procedure?
    This is easy with modern C++.
    (Edit: code is incorrect, see post # 12)
    Code:
    #include <thread>
    
    void CDLG::some_function()
    {
    	CString strFileName="abc.doc";
    	std::thread(std::bind(ProcessContentThreadFunction, strFileName));
    }
    
    void ProcessContentThreadFunction(CString fileName)
    {
    	// process the file
    }
    If your compiler doesn't support std::thread, you can use boost::thread instead.
    Last edited by D_Drmmr; April 4th, 2013 at 03:21 AM. Reason: added note
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured