Subject: |
Re: How to ensure epicsThread function is running in short-lived environment? |
From: |
Dirk Zimoch via Core-talk <[email protected]> |
To: |
<[email protected]> |
Date: |
Wed, 3 Apr 2019 11:37:40 +0200 |
Hi Martin,
Try on a system that supports thread priorities (on Linux that requires
to run the ioc as root ... or maybe to use "capabilities" which I never
found out how to use without being root in the first place) and use a
higher priority for the new thread than for the parent thread.
Without priorities, I think the only way would be to use event
semaphores like this:
void myThread::run()
{
std::cerr << "myThread::run() begin\n";
epicsThreadSleep(3);
std::cerr << "myThread::run() end\n";
epicsEventSignal(done);
}
int main() {
{
myThread t1(0, "foo");
epicsEventWait(done);
}
}
Wait inside the {} before your thread object goes out of context and the
destructor is called.
Actually it may also work with putting the epicsThreadSleep(); inside
the {}:
int main() {
{
myThread t1(0, "foo");
epicsThreadSleep(5);
}
}
I have not tested anything of the above. So it may or may not work.
Dirk
On 02.04.19 23:35, Konrad, Martin via Core-talk wrote:
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
- References:
- How to ensure epicsThread function is running in short-lived environment? Konrad, Martin via Core-talk
- Navigate by Date:
- Prev:
a question on a commit comment Jeong Han Lee via Core-talk
- Next:
Re: EPICS 7.0.2.1 release preparation 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
- Navigate by Thread:
- Prev:
How to ensure epicsThread function is running in short-lived environment? Konrad, Martin via Core-talk
- Next:
Re: How to ensure epicsThread function is running in short-lived environment? Michael Davidsaver 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
|