From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15710 invoked by alias); 22 Dec 2008 13:19:08 -0000 Received: (qmail 15701 invoked by uid 22791); 22 Dec 2008 13:19:07 -0000 X-SWARE-Spam-Status: No, hits=3.3 required=5.0 tests=BARRACUDA_BRBL,BAYES_50,J_CHICKENPOX_37,MIME_QP_LONG_LINE X-Spam-Check-By: sourceware.org Received: from pioneerwireless.ca (HELO pioneerwireless.ca) (72.172.130.178) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 22 Dec 2008 13:18:21 +0000 Received: (qmail 14408 invoked by uid 48); 22 Dec 2008 08:18:19 -0500 Received: from 24.139.16.66 ([24.139.16.66]) by webmail.pioneerwireless.ca (Horde MIME library) with HTTP; Mon, 22 Dec 2008 08:18:19 -0500 Message-ID: <20081222081819.lgug4d45d9ssksgg@webmail.pioneerwireless.ca> Date: Mon, 22 Dec 2008 13:19:00 -0000 From: "John E. Bossom" To: pthreads-win32@sourceware.org Subject: Re: pthread related issues References: <46333.1920.qm@web55808.mail.re3.yahoo.com> In-Reply-To: <46333.1920.qm@web55808.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.1.6) X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2008/txt/msg00074.txt.bz2 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 : > Hi, > > I have installed windows pthread-win32 pthreadGC2 dll(WINDOWS XP). I=20=20 > see my multithreaded windows program crashing at different=20=20 > locations when i am handling I/O. If i use gdb, the program is=20=20 > able to run. For the below program sometimes crahes at ifstream=20=20 > fin(..) > > int ConfigData::fillConfigData(char *p_cFileName) > { > int iStatus =3D 1; > char pcPort[10]; > > ifstream fin(p_cFileName, ifstream::in)---> crashes sometimes her= e. > > //fin.getline(m_pcUrl,MAX_URL_LEN); > //cout << "----- fillConfigData URL :" << m_pcUrl< > fin.getline(pcPort,10); > m_iPort =3D 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=20=20=20 > tried compilation both with and without -mthreads options. But the=20=20= =20 > problem persists. > > > Am i missing something. > > > Suggestions appreciated. > > Thanks, > Jay > > > > > >