Effacer les filtres
Effacer les filtres

Multi-threaded Mex functions in the FEX

3 vues (au cours des 30 derniers jours)
Jan
Jan le 20 Déc 2011
Modifié(e) : Jan le 6 Jan 2018
I've published some C-Mex functions in the FEX, which could benefit from multi-threading. I like to keep the function compatible with Windows, Linux and MacOS.
While I have some experiences with using _beginthreadex and _endthreadex under Windows, I have not worked with the pthread libraries under Linux. Although I can use pthread under Windows also, I do not want to increase the requirements for the users any further - even the compilation with the "mex" command is too confusing for some users already.
OpenMP is not available in the free MSVC Express compilers. And installing MinGW to compile the Mex files is not trivial also.
What are simple solutions for a platform independent multi-threading in C- or C++-Mex-functions?
  2 commentaires
Jan
Jan le 22 Déc 2011
[BUMP] I admit, I'm not very surprised, that there is no answer, because my corresponding search in the net has not been successful either. I think the 2 votes mean, that there is a need for a solution.
Yair Altman
Yair Altman le 6 Mar 2014
I believe that using winpthreads-32 (which works on Win64 as well as Win32, despite the name) is easier than MinGW. See my latest article on UndocumentedMatlab.com. Since Pthreads are natively supported on Macs & Linux, this could be the winning combination.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Déc 2011
pthreads (Posix Threads) is the only standardized and [supposedly] platform-independent threading for C.
pthreads was incorporated in to the POSIX standards as of 1995, so I do not expect it to be available for embedded systems, as a bunch of those pretty much froze as of 1990-ish capabilities (the POSIX standards added after 1900 tend to be relatively high overhead in order to support generality.)
My understanding from when I used to be active in comp.lang.c is that Windows threading is incompatible with POSIX threads, that it is not just a matter of translating calls but that Windows threading does something or other in an way that contradicts POSIX. I was, however, not interested enough to bother to check that out myself.
A list (as of 2006) of all known multithreading libraries for Unix operating systems.
Apache Portable Runtime (APR) offers a portable interface to OS threads
See also several others (mostly for C++) listed at http://www.shlomifish.org/open-source/portability-libs/
  2 commentaires
Jan
Jan le 22 Déc 2011
Thank you very much!
Jan
Jan le 25 Fév 2012
Matlab 2009a and 2011b/Windows are shipped with some boost libraries. Does this concern the Mac and Linux versions also? Can they be used for a standardize multi-threading support?

Connectez-vous pour commenter.

Plus de réponses (2)

Peter Li
Peter Li le 3 Juil 2012
With C++11 your general problem should be solved? Search stackoverflow (or perhaps Matlab answers) for how to compile mex with C++11.
Even if you get C++11 working, C++ multithreading is not much fun, so I recommend instead using the Theron Actors library. It's nice to do multithreading under the Actors model and this library is pretty efficient and very well documented. And it allows you to flexibly link in different threading solutions.
The only problem with this is that if you use boost-thread for the threading under Linux the linking step will conflict with the boost-thread Matlab uses internally, so that will require more struggling with mex to get working.
  1 commentaire
Jan
Jan le 3 Juil 2012
Are the boost-libs shipped with Matlab sufficient already?

Connectez-vous pour commenter.


Jan
Jan le 6 Sep 2012
Modifié(e) : Jan le 6 Jan 2018
Unfortunately:
Note: this requires a C++ compiler with C++11 (formerly known as C++0x)
support. Ubuntu 12.04 works right out of the box, Visual Studio 2010 would
require third-party implementation of std::thread.
Asking the FEX users to install a (non free) third-party implementation of str::thread is not sufficient. I get a lot of questions concerning "mex -setup" already.

Catégories

En savoir plus sur C Shared Library Integration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by