Hi,
I have a bunch of unit tests for support modules that spawn epicsThreads
and tear them down after a very short time. I noticed that although I'm
waiting for the thread to shut down cleanly tests are not reproducible.
In the attached simple code snipped I sometimes see the thread function
running:
$ time ./a.out
myThread::myThread() begin
myThread::myThread() end
myThread::~myThread() begin
myThread::run() begin
myThread::run() end
myThread::~myThread() end
real 0m8.044s
user 0m0.025s
sys 0m0.024s
However, sometimes the destructor gets called so fast that the thread
function doesn't run:
$ time ./a.out
myThread::myThread() begin
myThread::myThread() end
myThread::~myThread() begin
myThread::~myThread() end
real 0m5.041s
user 0m0.014s
sys 0m0.031s
I'm wondering if there is a way I can ensure run() always runs. I'm
wondering if making the constructor wait until run() actually starts
executing.
Thanks,
Martin
--
Martin Konrad
High Performance Controls Team Leader
Facility for Rare Isotope Beams
Michigan State University
640 South Shaw Lane
East Lansing, MI 48824-1321, USA
Tel. 517-908-7253
Email: [email protected]
// compile with g++ -I /usr/lib/epics/include -I /usr/lib/epics/include/os/Linux/ -I /usr/lib/epics/include/compiler/gcc/ -L /usr/lib/epics/lib/linux-x86_64 epicsThread.cpp -lCom
#include <iostream>
#include <epicsThread.h>
class myThread: public epicsThreadRunable {
public:
myThread(int arg,const char *name);
virtual ~myThread();
virtual void run();
epicsThread thread;
};
myThread::myThread(int arg,const char *name) : thread(*this,name,epicsThreadGetStackSize(epicsThreadStackSmall),50)
{
std::cerr << "myThread::myThread() begin\n";
thread.start();
std::cerr << "myThread::myThread() end\n";
}
myThread::~myThread() {
std::cerr << "myThread::~myThread() begin\n";
thread.exitWait();
std::cerr << "myThread::~myThread() end\n";
}
void myThread::run()
{
std::cerr << "myThread::run() begin\n";
epicsThreadSleep(3);
std::cerr << "myThread::run() end\n";
}
int main() {
{
myThread t1(0, "foo");
}
epicsThreadSleep(5);
}
- Replies:
- Re: How to ensure epicsThread function is running in short-lived environment? Dirk Zimoch via Core-talk
- Re: How to ensure epicsThread function is running in short-lived environment? Michael Davidsaver via Core-talk
- Navigate by Date:
- Prev:
Re: EPICS 7 incompatibility in errMdef.h Johnson, Andrew N. via Core-talk
- Next:
Re: [Merge] ~bhill/epics-base:pvAccess-envDefs.h into epics-base:7.0 Bruce Hill via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
<2019>
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
[Merge] ~anj/epics-base/+git/base-7.0:loadable-err-syms into epics-base:7.0 Andrew Johnson via Core-talk
- Next:
Re: How to ensure epicsThread function is running in short-lived environment? Dirk Zimoch via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
<2019>
2020
2021
2022
2023
2024
|