This workflow can usually be achieved using a "Code Replacement Library" (CRL).
Note that below workaround works only with Embedded Coder as using CRLs is only available in Embedded Coder.
However, as of MATLAB R2022b, changing the "Hardware Implementation" to "Intel x86-64 (Linux)" and the "Code Replacement Library" to Linux libraries does not achieve the needed workflow.
In order to achieve the above workflow (POSIX style of implementing data synchronization and mutex locks) you can use the attached CRL which will swap the Windows functions used for their POSIX counterpart. To use the attached CRL, please follow the steps below:
- Download the files "rtw_linux_tfl_table_tmw.m" and "rtw_linux_table_tmw.mat".
- Execute the command "crtool" in MATLAB Command line.
- In the "Code Replacement - Manage Libraries" app that is opened, click on "Open" on the upper left corner and select "rtw_linux_code" in the Code Replacement Tool.
- Click on "Generate Registration File" and add it to a folder on your MATLAB Path give the replacement register a name like "linux_semaphore".
- Type and run "sl_refresh_customizations" in the MATLAB command line.
- In your model settings go to Code Generation/Interface and click on "Select" on the "Code Replacement libraries" line.
- You should see an "linux_semaphore" entry (or whatever you named your file), click on it and click on the right arrow.
- You should see "linux_semaphore" next to "Code Replacement Libraries". Generate code, and it should not use Windows functions.
Please ensure that you have downloaded both the M file and the MAT file in the same location. Also, ensure that before code generation, you have chosen the following values in the "Configuration Parameters > Hardware Implementation" pane:
- Device vendor = "Intel"
- Device type = "x86-64 (Linux 64)"
Please note that this CRL is tested for the above vendor and type combination. In case of a different combination, please keep in mind that this CRL might be susceptible to failure in corner cases.
Please refer to the CRL documentation for further information on using developing and using Code Replacement Libraries.