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 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 and modified it in PR #51