public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* pthread related issues
@ 2008-12-22  7:22 jayshankar nair
  2008-12-22 13:19 ` John E. Bossom
  0 siblings, 1 reply; 2+ messages in thread
From: jayshankar nair @ 2008-12-22  7:22 UTC (permalink / raw)
  To: pthreads-win32

Hi,

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 fin(..)

int ConfigData::fillConfigData(char *p_cFileName)
{
        int iStatus = 1;
        char pcPort[10];

        ifstream fin(p_cFileName, ifstream::in)---> crashes sometimes here.

        //fin.getline(m_pcUrl,MAX_URL_LEN);
        //cout << "----- fillConfigData URL :" << m_pcUrl<<endl;

        fin.getline(pcPort,10);
        m_iPort = atoi(pcPort);
        cout << "----- fillConfigData port :" << m_iPort << endl;

        fin.getline(m_pcMethod,MAX_CALLBACK_METHOD_NAME_LEN);
        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 problem persists.


Am i missing something.


Suggestions appreciated.

Thanks,
Jay




      

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: pthread related issues
  2008-12-22  7:22 pthread related issues jayshankar nair
@ 2008-12-22 13:19 ` John E. Bossom
  0 siblings, 0 replies; 2+ messages in thread
From: John E. Bossom @ 2008-12-22 13:19 UTC (permalink / raw)
  To: pthreads-win32

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
    it is.

Assuming your little snippet, below, is accessing that file from
more than one thread, you are going to have to synchronize access to
that file/stream.

Hope that helps,

John E. Bossom

Quoting jayshankar nair <n_jayshankar@yahoo.com>:

> Hi,
>
> 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  
> fin(..)
>
> int ConfigData::fillConfigData(char *p_cFileName)
> {
>         int iStatus = 1;
>         char pcPort[10];
>
>         ifstream fin(p_cFileName, ifstream::in)---> crashes sometimes here.
>
>         //fin.getline(m_pcUrl,MAX_URL_LEN);
>         //cout << "----- fillConfigData URL :" << m_pcUrl<<endl;
>
>         fin.getline(pcPort,10);
>         m_iPort = atoi(pcPort);
>         cout << "----- fillConfigData port :" << m_iPort << endl;
>
>         fin.getline(m_pcMethod,MAX_CALLBACK_METHOD_NAME_LEN);
>         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   
> problem persists.
>
>
> Am i missing something.
>
>
> Suggestions appreciated.
>
> Thanks,
> Jay
>
>
>
>
>
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-22 13:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-22  7:22 pthread related issues jayshankar nair
2008-12-22 13:19 ` John E. Bossom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).