Mex Multithreading

버전 1.0.0.0 (3.11 KB) 작성자: Dirk-Jan Kroon
Example of (Windows) multi-threading in a MEX file
다운로드 수: 4.8K
업데이트 날짜: 2008/9/2

라이선스 보기

편집자 메모: This file was selected as MATLAB Central Pick of the Week

Nowadays, Matlab is multi-threaded but most MEX files are still single threaded. This is an simple example of c-code for MEX file multi-threading.

The mex function "y = square(x)" is written in c-code and starts 2 worker threads. The first worker thread will square all values on the even input indexes x[0] x[2] .. x[n], and the second worker thread all odd indexes x[1] x[3] .. x[n]. Also demonstrates thread safety by using Mutex to lock percentage variable.

example,
mex square.c -v;
y = square([1 2 3 4 5 6 7 8 9])

note:
The function uses <windows.h> (function sleep ) and <process.h> ( function _beginthreadex ) which are included with visual studio and some other compilers.

This example is tested with Windows Vista 64 and Visual Studio 2008 compiler, and with (default) LCC compiler and Vista 32.

인용 양식

Dirk-Jan Kroon (2026). Mex Multithreading (https://kr.mathworks.com/matlabcentral/fileexchange/21233-mex-multithreading), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2008a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 MATLAB Compiler에 대해 자세히 알아보기
버전 게시됨 릴리스 정보
1.0.0.0

Now also works with the Matlab LCC compiler.