Is the C API thread-safe?

I am working on an application that spawns a thread from a modified rt_lx_main.cpp at model startup and subsequently sets parameters in the Simulink model using the C API interface. I plan on doing this at startup as well as during run time. If I do this a run time, is there any issue of data corruption, or in other words is the C-API thread safe? I only plan on running one thread that will modify parameters in the Simulink model, but would me modifying this code from a thread during run time cause any issues with what happens in the model? I'm using Embedded Coder and G++ to build the model and associated Source Code.

回答 (2 件)

James Tursa
James Tursa 2017 年 2 月 17 日

1 投票

In general, mex API functions are not thread safe. In particular, any functions that allocate/deallocate memory (e.g. the mxCreateEtc, mxDestroyArray, mxFree, etc) are not thread safe. API functions that only "inquire" (e.g. mxGetPr, mxGetPi, etc) would probably be thread safe.
Maxwell Bezold
Maxwell Bezold 2017 年 2 月 21 日
編集済み: Maxwell Bezold 2017 年 2 月 21 日

0 投票

So I am not talking about mex functions running natively in Simulink, but rather about accessing memory in the model through the C-API interface on a real time Embedded Coder target. (e.g. the parameters made accessible when I click the signals and parameter boxes in the attached photo)

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

質問済み:

2017 年 2 月 17 日

編集済み:

2017 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by