EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: EPICS thread problem on cygwin-x86
From: "Mark Rivers" <[email protected]>
To: "Eric Norum" <[email protected]>
Cc: <[email protected]>
Date: Fri, 27 Apr 2007 13:58:11 -0500
Eric,

1) Does putting the epicsThreadSleep(.001); into the thread wrapper
function that actually invokes the EPICS thread fix things?

No.  I have simplified the program even more, eliminating the
epicsEvent.  I just spawn a thread that either returns immediately or
sleeps for .001 second.  The wrapper function now sleeps for 5 seconds
after spawning the thread.  It still behaves the same, i.e. if the
spawned thread sleeps for .001 second all is well, and the calling
function sleeps for 5 seconds and prints a message. If it does not sleep
then it crashes.

2) Have you tried running this under gdb to see where the crash occurs?

I have found that gdb under Cygwin does not run the threaded EPICS
applications at all.  Maybe I'm doing something wrong, but what works on
Linux does not work on Cygwin.  Furthermore, Cygwin does not produce a
useful core file.  It produces a file called, in this case
"threadTest.exe.stackdump", but it simply contains:

$ cat threadTest.exe.stackdump
Exception: STATUS_ACCESS_VIOLATION at eip=004A05B6
eax=DF0DF046 ebx=004E6F60 ecx=6112CB58 edx=005A2DC0 esi=005A2DC0
edi=610E30A0
ebp=0022EDD8 esp=0022EDD4
program=j:\epics\devel\threadTest\bin\cygwin-x86\threadTest.exe, pid
4028, thread main
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame     Function  Args
0022EDD8  004A05B6  (004E6F60, 005A2DC0, 0022EE08, 005A2DC8)
0022EDF8  004918A7  (610E30A0, 004D94F4, 004D9747, 6110A4F0)
0022EE28  0049220E  (004C9438, 0000000A, 00020000, 00401520)
0022EE48  00401593  (00543BD8, 0022EEE8, 00000000, 005407A4)
0022EEF8  00418070  (61157780, FFFFFFFF, 00000000, 004015F3)
0022EF18  0040161E  (00000002, 61157668, 00540090, 77FA88F0)
0022EFD8  61004DD2  (0022EFF0, 00000000, 0022F221, 33323430)
0022FF88  6100594F  (00000000, 00000000, 00000000, 00000000)
End of stack trace


Here is the new version of the program:

/***************************************************/
#include <epicsThread.h>
#include <epicsExport.h>
#include <iocsh.h>

static void myThread(int *delay)
{
    if (*delay) epicsThreadSleep(.001);
}


static void threadTest(int delay)
{
    epicsThreadCreate("myThread",
          epicsThreadPriorityLow,
          epicsThreadGetStackSize(epicsThreadStackSmall),
          (EPICSTHREADFUNC)myThread, &delay);
    printf("Sleeping 5 seconds\n");
    epicsThreadSleep(5.0);
}

/* iocsh functions */

static const iocshArg threadArg0 = {"Delay",       iocshArgInt};
static const iocshArg * const threadArgs[1] = {&threadArg0};
static const iocshFuncDef threadTestFuncDef= {"threadTest", 1,
threadArgs};
static void threadTestCallFunc(const iocshArgBuf *args)
{
    threadTest(args[0].ival);
}
static void threadTestRegister(void)
{
    iocshRegister(&threadTestFuncDef, threadTestCallFunc);
}
epicsExportRegistrar(threadTestRegister);
/***************************************************/

Here is the output:

$ ../../bin/cygwin-x86/threadTest.exe st.cmd
#!../../bin/linux-x86/example
## You may have to change example to something else
## everywhere it appears in this file
#< envPaths
## Register all support components
dbLoadDatabase("../../dbd/threadTest.dbd",0,0)
threadTest_registerRecordDeviceDriver(pdbbase)
iocInit()
Starting iocInit
########################################################################
####
###  EPICS IOC CORE built on Aug 25 2006
###  EPICS R3.14.8.2 $R3-14-8-2$ $2006/01/06 15:55:13$
########################################################################
####
iocInit: All initialization complete
threadTest 1
Sleeping 5 seconds
threadTest 0
pthread_create error Resource temporarily unavailable
Segmentation fault (core dumped) 


Mark


> -----Original Message-----
> From: Eric Norum [mailto:[email protected]] 
> Sent: Friday, April 27, 2007 1:16 PM
> To: Mark Rivers
> Cc: [email protected]
> Subject: Re: EPICS thread problem on cygwin-x86
> 
> 1) Does putting the epicsThreadSleep(.001); into the thread wrapper  
> function that actually invokes the EPICS thread fix things?
> 2) Have you tried running this under gdb to see where the 
> crash occurs?
> 
> On Apr 27, 2007, at 1:01 PM, Mark Rivers wrote:
> 
> > Folks,
> >
> > I have found a problem with EPICS threads on cygwin-x86.  
> The problem
> > showed up when doing the command "asynReport" with the "details"
> > argument=0 (default). The IOC crashes when this is done.  It is a  
> > timing
> > problem with the thread that asynReport creates.
> >
> > I have come up with a very simple test program to demonstrate the
> > problem:
> >
> > /**************************************************************/
> > #include <epicsEvent.h>
> > #include <epicsThread.h>
> > #include <epicsExport.h>
> > #include <iocsh.h>
> >
> > typedef struct myArgs {
> >     epicsEventId done;
> >     int  delay;
> > } myArgs;
> >
> > static void myThread(myArgs *pArgs)
> > {
> >     if (pArgs->delay) epicsThreadSleep(.001);
> >     epicsEventSignal(pArgs->done);
> > }
> >
> > static void threadTest(int delay)
> > {
> >     myArgs args;
> >     epicsEventId done = epicsEventMustCreate(epicsEventEmpty);
> >
> >     args.delay = delay;
> >     args.done = done;
> >     epicsThreadCreate("myThread",
> >           epicsThreadPriorityLow,
> >           epicsThreadGetStackSize(epicsThreadStackSmall),
> >           (EPICSTHREADFUNC)myThread, &args);
> >     epicsEventMustWait(done);
> >     epicsEventDestroy(done);
> > }
> >
> > /* iocsh functions */
> > static const iocshArg threadArg0 = {"Delay",       iocshArgInt};
> > static const iocshArg * const threadArgs[1] = {&threadArg0};
> > static const iocshFuncDef threadTestFuncDef= {"threadTest", 1,
> > threadArgs};
> > static void threadTestCallFunc(const iocshArgBuf *args)
> > {
> >     threadTest(args[0].ival);
> > }
> > static void threadTestRegister(void)
> > {
> >     iocshRegister(&threadTestFuncDef, threadTestCallFunc);
> > }
> > epicsExportRegistrar(threadTestRegister);
> > /**************************************************************/
> >
> > The function threadTest() simply creates a thread, and then waits  
> > for it
> > to complete with epicsEventMustWait().
> >
> > If the delay argument is non-zero the thread sleeps for 
> 0.001 second.
> > It then signals the event and returns.
> >
> > On Linux this program works fine.
> >
> > However, on Cygwin it crashes if delay is 0, i.e. if it 
> does not sleep
> > for .001 second.
> >
> > $ ../../bin/cygwin-x86/threadTest.exe st.cmd
> > #!../../bin/linux-x86/example
> > ## You may have to change example to something else
> > ## everywhere it appears in this file
> > #< envPaths
> > ## Register all support components
> > dbLoadDatabase("../../dbd/threadTest.dbd",0,0)
> > threadTest_registerRecordDeviceDriver(pdbbase)
> > iocInit()
> > Starting iocInit
> > 
> ##############################################################
> ######## 
> > ##
> > ####
> > ###  EPICS IOC CORE built on Aug 25 2006
> > ###  EPICS R3.14.8.2 $R3-14-8-2$ $2006/01/06 15:55:13$
> > 
> ##############################################################
> ######## 
> > ##
> > ####
> > iocInit: All initialization complete
> > epics> threadTest 1
> > epics> threadTest 0
> > pthread_create error Resource temporarily unavailable
> > Segmentation fault (core dumped)
> >
> > This is a serious problem, since any thread that returns too quickly
> > causes a crash on Cygwin.
> >
> > Can someone who knows about EPICS threads figure out why this is
> > crashing, and how to fix it?
> >
> > Thanks,
> > Mark
> > <threadTest.c>
> > <threadTestInclude.dbd>
> > <threadTestMain.cpp>
> > <Makefile>
> 
> -- 
> Eric Norum <[email protected]>
> Advanced Photon Source
> Argonne National Laboratory
> (630) 252-4793
> 
> 
> 


Replies:
Re: EPICS thread problem on cygwin-x86 Eric Norum
References:
Re: EPICS thread problem on cygwin-x86 Eric Norum

Navigate by Date:
Prev: [Fwd: New for Argonne National Laboratory Employees - Your Quarterly Newsletter from National Instruments] Ned D. Arnold
Next: Re: EPICS thread problem on cygwin-x86 Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: EPICS thread problem on cygwin-x86 Eric Norum
Next: Re: EPICS thread problem on cygwin-x86 Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  <20072008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Nov 2011 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·