EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Matlab 2020b crashes with labCA 3.7.2
From: "Johnson, Andrew N. via Core-talk" <core-talk at aps.anl.gov>
To: EPICS core-talk <core-talk at aps.anl.gov>
Cc: Till Straumann <till.straumann at psi.ch>
Date: Fri, 5 Mar 2021 17:14:50 +0000
On Mar 5, 2021, at 8:50 AM, Till Straumann via Tech-talk <tech-talk at aps.anl.gov> wrote:

The deadlock happens when matlab
 - loads a shared object (or library)
 - AND the shared object executes some initialization code (e.g., constructors of global objects defined in the library)
 - AND the initialization code calls 'pthread_join()'. 'pthread_join()' then never returns.

Note that if 'ordinary' code in the shared object (i.e., as opposed to initialization code) uses 'pthread_join()' then
that works fine.

EPICS' libCom does use 'pthread_join()' during initialization and is therefore affected.

At this point I can suggest two possible work-arounds (using one of them is sufficient):

1.) Use an EPICS-base build with posix priority scheduling disabled. This avoids a section of initialization
     code which calls 'pthread_join()'

The init code that Till is referring to has been in osi/os/posix/osdThread.c since 2011:

static void findPriorityRange(commonAttr *a_p)
{
priAvailable arg;
pthread_t    id;
void         *dummy;
int          status;

    arg.policy = a_p->schedPolicy;
    arg.ok = 0;

    status = pthread_create(&id, 0, find_pri_range, &arg);
    checkStatusOnceQuit(status, "pthread_create","epicsThreadInit");

    status = pthread_join(id, &dummy);
    checkStatusOnceQuit(status, "pthread_join","epicsThreadInit");

    a_p->minPriority = arg.min_pri;
    a_p->maxPriority = arg.max_pri;
    a_p->usePolicy = arg.ok;
}

When posix priority scheduling is enabled this gets called from inside the once() routine that the Posix epicsThreadInit() implementation runs using pthread_once(). I don’t see an easy way to avoid doing that initialization here; it might be possible by adding more lazy-init logic to only look up the min and max scheduling priorities when they are actually needed, but I suspect that would still be before the end of the initialization code.

Hence not something we should try to fix IMHO.

- Andrew

-- 
Complexity comes for free, simplicity you have to work for.


Replies:
Re: Matlab 2020b crashes with labCA 3.7.2 Michael Davidsaver via Core-talk

Navigate by Date:
Prev: Build failed: epics-base base-integration-642 AppVeyor via Core-talk
Next: Re: Matlab 2020b crashes with labCA 3.7.2 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  <20212022  2023  2024 
Navigate by Thread:
Prev: Build failed: epics-base base-integration-642 AppVeyor via Core-talk
Next: Re: Matlab 2020b crashes with labCA 3.7.2 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  <20212022  2023  2024 
ANJ, 05 Mar 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·