How can I call M fuctions in different thread in mex coding matlab and C++?

조회 수: 1 (최근 30일)
Matlab 2019b
I tried to use mexCallMATLAB in the new thread, but failed.
is there any other way to realize that calling M functions in different thread in mex coding matlab and C++?
the following is my code,hello() is a M function:
#include "mex.h"
#include <thread>
#include <stdio.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
std::thread t(mexCallMATLAB(nlhs,(mxArray**)(&plhs[0]),nrhs,(mxArray**)(&prhs[0]),"hello"));
t.join();
}

채택된 답변

Bruno Luong
Bruno Luong 2021년 7월 27일
No you cannot. MATLAB will crash since many MATLAB functions are not thread safe.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by