我尝试从单独的线程运行c函数时遇到问题,我为每个收集数据的函数创建了两个线程,并将其返回到blt图中。如果我不使用线程并逐个运行它工作正常,问题只是当我尝试将它们放入线程时。我得到了不同的错误,但双重免费或腐败是其中之一,但一直显示回溯和内存映射。
TCL代码:
proc graphReport {sampleID repstart repstop} {
global xtemp yBio yPart currFrame
#contents has the result for bio and particles for every second
graphCreation
tsv::set graph xtemp_shared 0
tsv::set graph yBio_shared 0
tsv::set details sampleid_shared $sampleID
tsv::set details repstart_shared $repstart
tsv::set details repstop_shared $repstop
#puts "[tsv::get details sampres_shared] [tsv::get details repstart_shared] [tsv::get details repstop_shared]"
thread::create {
load ./samples.so
connectDB2
set temp [getEpoch [tsv::get details sampleid_shared] [tsv::get details repstart_shared] [tsv::get details repstop_shared]]
tsv::set graph xtemp_shared $temp
}
set xtemp [tsv::get graph xtemp_shared]
#set xtemp [getEpoch $sampleID $repstart $repstop] <-- one by one works fine
set xtemp [split $xtemp ","]
set xtemp [string trimleft $xtemp {\{}]
set xtemp [string trimright $xtemp {\}}]
thread::create {
load ./samples.so
connectDB2
tsv::set graph yBio_shared [getBio [tsv::get details sampleid_shared] [tsv::get details repstart_shared] [tsv::get details repstop_shared]]
}
set yBio [tsv::get graph yBio_shared]
#set yBio [getBio $sampleID $repstart $repstop] <-- one by one works fine
set yBio [split $yBio ","]
set yBio [string trimleft $yBio {\{}]
set yBio [string trimright $yBio {\}}]
C Code getBio:
static int getBio(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]){
Tcl_Obj *result;
char sampleid[15];
char repStartTime[256];
char repStopTime[256];
int length;
int lengthTwo;
int lengthThree;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "number of argument error");
return TCL_ERROR;
}
strcpy(sampleid, Tcl_GetStringFromObj(objv[1], &lengthThree));
strcpy(repStartTime, Tcl_GetStringFromObj(objv[2], &length));
strcpy(repStopTime, Tcl_GetStringFromObj(objv[3], &lengthTwo));
char command[256];
PQclear(res);
strcpy(command, "Select \"bioresults\"('");
strcat(command, sampleid);
strcat(command,"','");
strcat(command, repStartTime);
strcat(command,"','");
strcat(command, repStopTime);
strcat(command, "')");
printf("%s\n",command);
res = PQexec(conn,command);
result = Tcl_GetObjResult(interp);
Tcl_SetStringObj(result, PQgetvalue(res,0,0), strlen(PQgetvalue(res,0,0)));
return TCL_OK;
}
C Code epoch:
static int getEpoch(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]){
Tcl_Obj *result;
char sampleid[15];
char repStartTime[256];
char repStopTime[256];
int length;
int lengthTwo;
int lengthThree;
char * buffer;
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "number of argument error");
return TCL_ERROR;
}
strcpy(sampleid, Tcl_GetStringFromObj(objv[1], &lengthThree));
strcpy(repStartTime, Tcl_GetStringFromObj(objv[2], &length));
strcpy(repStopTime, Tcl_GetStringFromObj(objv[3], &lengthTwo));
char command[256];
PQclear(res);
strcpy(command, "Select \"epochtime\"('");
strcat(command, sampleid);
strcat(command,"','");
strcat(command, repStartTime);
strcat(command,"','");
strcat(command, repStopTime);
strcat(command, "')");
printf("%s\n",command);
res = PQexec(conn,command);
result = Tcl_GetObjResult(interp);
Tcl_SetStringObj(result, PQgetvalue(res,0,0), strlen(PQgetvalue(res,0,0)));
return TCL_OK;
}