you can use CriticalSection,
for example, if you use MFC, the code may like below:
<pre lang="cs">#include "afxmt.h"
CCriticalSection critical_section;
static void Split_Into_Path_And_File(char * const SaveAs,
std::string & Path,
std::string & File)
{
std::string const temp(SaveAs);
critical_section.Lock();
//find the folder name to use to name the 7z file
size_t last=temp.find_last_of('\\');
File=temp.substr(last+1, temp.size()-last-1);
Path=temp.substr(0, last);
critical_section.Unlock();
}