This is the mail archive of the
mailing list for the pthreas-win32 project.
Re: pthread related issues
- From: "John E. Bossom" <drifting at pioneerwireless dot ca>
- To: pthreads-win32 at sourceware dot org
- Date: Mon, 22 Dec 2008 08:18:19 -0500
- Subject: Re: pthread related issues
- References: <email@example.com>
The C++ stream libraries are not thread safe....
That is to say, if you have more than one thread operating on the
same instance of a stream, undefined results will occur.
Why would it crash on Windows and not linux....?
1) actual implementation of the stream library is different
2) thread scheduling... the crash is random based upon thread context
switching... running a program within the debugger effectively
changes it's behavour... you now have a debugger in there possibily
slowing down or otherwise affecting the scheduling. For a well behaved
thread app this isn't a problem... but for one with race conditions
Assuming your little snippet, below, is accessing that file from
more than one thread, you are going to have to synchronize access to
Hope that helps,
John E. Bossom
Quoting jayshankar nair <firstname.lastname@example.org>:
I have installed windows pthread-win32 pthreadGC2 dll(WINDOWS XP). I
see my multithreaded windows program crashing at different
locations when i am handling I/O. If i use gdb, the program is
able to run. For the below program sometimes crahes at ifstream
int ConfigData::fillConfigData(char *p_cFileName)
int iStatus = 1;
ifstream fin(p_cFileName, ifstream::in)---> crashes sometimes here.
//cout << "----- fillConfigData URL :" << m_pcUrl<<endl;
m_iPort = atoi(pcPort);
cout << "----- fillConfigData port :" << m_iPort << endl;
cout << "----- fillConfigData method: " << m_pcMethod<< endl;
I am able to run the same program with linux.
For compilation, i include -lpthreadGC2(libthreadGC2.dll). I have
tried compilation both with and without -mthreads options. But the
Am i missing something.