MATLAB Answers

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

2 ビュー (過去 30 日間)
ian gong
ian gong 2021 年 7 月 27 日
回答済み: Bruno Luong 2021 年 7 月 27 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by