c - how to pass blt vectors in a separate thread -
i have function phone call database, i'm using c , tcl/tk tcl calls of function gets executed in c, while happening scheme in tcl hangs time process query phone call , time fills vectors, want tcl application go on working , have process in separate thread. i'm trying right now.
c function process database phone call , fills vectors:
static int getepochprototype(clientdata cdata, tcl_interp *interp, int objc, tcl_obj *const objv[]){ tcl_obj *result; char sampleid[15]; char tclxvec[15]; char tclyvec[15]; int length; int numresults; int i; blt_vector *xcvec, *ycvec; if (objc != 4) { tcl_wrongnumargs(interp, 3, objv, "number of argument error"); homecoming tcl_error; } strcpy(sampleid,tcl_getstringfromobj(objv[1], &length)); strcpy(tclxvec,tcl_getstringfromobj(objv[2], &length)); strcpy(tclyvec,tcl_getstringfromobj(objv[3], &length)); if (blt_vectorexists(interp, tclxvec) != tcl_ok || blt_vectorexists(interp, tclyvec) != tcl_ok) { if ((blt_getvector(interp, tclxvec, &xcvec) != tcl_ok) || (blt_getvector(interp, tclyvec, &ycvec) != tcl_ok)) { homecoming tcl_error; } } else { printf("vector not found \n"); homecoming tcl_error; } char command[256]; pqclear(res); strcpy(command, "select extract ('epoch' \"timestamp\"), \"bioaccumulated\" \"results\" \"sampleid\" = '"); strcat(command, sampleid); strcat(command, "' order \"timestamp\" asc"); res = pqexec(conn,command); numresults = pqntuples(res); double x[numresults], y[numresults]; (i = 0; < numresults; i++) { x[i] = strtod(pqgetvalue(res,i,0), null); y[i] = strtod(pqgetvalue(res,i,1), null); } /* set info blt vectors */ if ((blt_resetvector(xcvec, x, numresults, numresults, tcl_volatile) != tcl_ok) || (blt_resetvector(ycvec, y, numresults, numresults, tcl_volatile) != tcl_ok)) { homecoming tcl_error; } homecoming tcl_ok; } tcl function trying send blt vectors c thread:
blt::vector create xvec blt::vector create yvec tsv::set graph xtemp_shared xvec tsv::set graph ybio_shared yvec thread::create { load ./samples.so connectdb2 #puts "[tsv::get details sampleid_shared]" getepochprototype [tsv::get details sampleid_shared] [tsv::get graph xtemp_shared] [tsv::get graph ybio_shared] } when seek "vector not found", print statement set when vectors cant found or there error, there way or missing ?
tcl's threading model requires access particular instance of tcl interpreter thread created interpreter. (tcl's implementation uses thread-specific info extensively.) can fill c arrays thread — usual c parallelism rules there — , utilize tcl_threadqueueevent tell other thread you've got do; message send code+data.
struct donereadingintoarraysevent { tcl_event eventheader; tcl_interp *interp; double *x, *y; int length; } struct donereadingintoarraysevent callback; callback.eventheader.proc = &mycallbackfunc; callback.interp = theinterphandleintheotherthread; callback.x = x; callback.y = y; callback.length = numberofvaluesinarray; tcl_threadqueueevent(mainthreadid, &callback.eventheader, tcl_queue_tail); now, in mycallbackfunc cast tcl_event* parameter struct donereadingintoarraysevent (safe; it's first member!) , retrieve values need tell interpreter (and interpreter in question).
for getting values tcl, i'd strongly consider using list tcl_obj containing whole bunch of double tcl_objs. mechanism wasn't available when blt first created, , might have improve performance you're expecting. or if number of values big , need pass them around and/or store them, send big chunk of binary (the binary scan command able pick bits out if needed).
relevant apis tcl_newlistobj, tcl_newdoubleobj , tcl_newbytearrayobj.
c multithreading tcl
No comments:
Post a Comment