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 x .. x[n], and the second worker thread all odd indexes x x .. x[n]. Also demonstrates thread safety by using Mutex to lock percentage variable.
mex square.c -v;
y = square([1 2 3 4 5 6 7 8 9])
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.