DiamondLightSource / DiamondLightSource/cothread
cothread should not unconditionally delete the EPICS context
- Dominant language
- C
- Stars
- 13
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
Currently `cothread.catools` registers an atexit handler which unconditionally calls `cadef.ca_context_destroy()`. This will destroy the context regardless of whether `cothread` was the one who created it. This is usually not a problem, but if `cothread` is used alongside `aioca` in the same thread then it is possible for `aioca` to create the EPICS context, for `cothread` to then delete it, and then `aioca` to also try and delete it. This causes a segfault.
`cothread` should keep track of whether it was the one who created the context - the return code for [ca_context_create](https://epics.anl.gov/base/R3-14/10-docs/CAref.html#ca_context_create) should tell us that. If we created the context we should destroy it inside the atexit handler, otherwise leave it alone.
`aioca` has added this mechanism in [PR #36](https://github.com/DiamondLightSource/aioca/pull/36) and modified it in [PR #51](https://github.com/DiamondLightSource/aioca/pull/51)
Contributor guide
Assessment
This issue has not been assessed yet.