After upgrading to Epics/Base 3.14.6 from 3.13.10 I am having
difficulty handling signals. In one of our applications if the user
does a control-C it is suppose to trap the signal and restore the PVs
to their original values. Odds are the control-c will occur while in a
ca_pend_event call. When I go to do a ca_pend_io in the interrupt
handler I get the error:
pthread_mutex_unlock failed: error Not owner
fatal error: epicsMutexOsdUnlock
I have included a simple program that displays the same problem. If
anyone knows the proper way of doing CA calls after catching a signal
please let me know.
Thanks,
--Bob Soliday
#include <stdio.h>
#include <strings.h>
#include <cadef.h>
#include <signal.h>
void interrupt_handler(int);
chid channelID[1];
char names[1][40];
int main(int argc, char **argv)
{
strcpy(names[0], "oag:H1:setCurrentC");
ca_task_initialize();
if (ca_search(names[0], &channelID[0])!=ECA_NORMAL) {
fprintf(stderr, "error: search failed for PV\n");
return(1);
}
if (ca_pend_io(10)!=ECA_NORMAL) {
fprintf(stderr, "error: search failed for PV\n");
return(1);
}
fprintf(stdout, "Found PV\n");
signal(SIGINT, interrupt_handler);
ca_pend_event(10);
ca_task_exit();
fprintf(stdout, "Done\n");
return(0);
}
void interrupt_handler(int sig) {
double value;
fprintf(stdout, "Interrupt detected\n");
if (ca_get(DBR_DOUBLE, channelID[0], &value)!=ECA_NORMAL) {
fprintf(stderr, "Error: unable to get value for PV\n");
}
if (ca_pend_io(10)!=ECA_NORMAL) {
fprintf(stderr, "Error: unable to get value for PV\n");
}
fprintf(stdout, "value = %lf\n", value);
}