we are working on an integration of the ps5000 library (libps5000_R1_3_6_6_3_x86_64) into MATLAB on a 64 Bit Ubuntu Linux platform. For this task we are using the mex interface of MATLAB. Controlling the scope and transferring data form the scope works quite well.
But there is a severe problem unloading the mex file (i.e. calling "clear mex" in MATLAB). When unloading the mex file Matlab crashes with a segmentation fault. Maybe we have an idea why the crash occurs:
/******************************************************************************/
/* MAIN */
/******************************************************************************/
int main(int argc, char *argv[]) {
short unithandle; /* handle to control the picoscope */
long a_bufferlen = 3000; /* length of buffer of CHANNEL A == trace length */
long timeIndisposedMs;
PICO_STATUS status = PICO_OK; /* return status of picoscope api calls */
printf("\nStart Block mode ... ");
status = ps5000RunBlock(
unithandle, /* short: scope handle */
0, /* long: pre trigger samples */
a_bufferlen, /* long: post trigger samples */
127, /* unsigned long: timebase */
1, /* short: oversampling, possible when timebase is smaller then max frequency, compute mean of neighbor samples */
&timeIndisposedMs, /* long: time that the scope will spent for collecting data */
0, /* unsigned short: zero based segment number */
CallbackBlockReady , /* pointer to callback function */
NULL /* optional parameter passed to callback function */
);
This program opens the scope, starts the block mode, and closes the
scope. Between this tasks the unix command line tool ps is called to print the
running threads of this application on the console.
Before opening the scope, only one thread, the main thread LWP=25824 is running. When the connection to the scope is open, three more threads are running (LWP=25827,25829,25830). In block mode one additional thread is running (LWP=25833). But AFTER CLOSING THE CONNECTION TO THE SCOPE, there is still an additional thread running (LWP=25827). I assume that this thread is not joined properly by the library and that this thread causes the MATLAB
crashes we observed when we clear the mex context. The crash may be caused by accesses to addresses freed by the MATLAB environment.
Is there any possibility to close this thread by a library call, or is there a bug in the libraray and we need an update for it?