I'm thinking of this already since some time, and it was part of my motivation switching to C++11.
I was delighted to see that what we do in system.c (encapsulate system functions such as threads
and shared memory) is now done natively in C++11, and it's done by experts and not amateurs like us.
I see that with std::timed_mutex and try_lock_for we have the desired timeout function. Pity that
C++11 does not contain inter-process communication like semaphores, so there we still have to use
our old functions.
But for threads switching to std::thread, I'm all in.
Stefan
> Hi, Stefan & co - now that midas is c++11 and c++11 comes with a threads library, should we
> switch midas to use the c++11 threads instead of pthreads? (Of course on Linux c++11
> threads are a layer on top of pthreads, the best I know).
>
> This should remove the dependency on pthreads.h and use a more native implementation of
> threads on MacOS and Windows. (again, the best I can tell).
>
> Of course this depends on c++11 threads having all the functions we need. Specifically, "lock
> with timeout" is useful to deal with "gah! everything stopped! what do I do!", a problem
> bedeviling midas in the early days (and still happens today!). Current midas kills everything
> after 5 minutes of deadlock - then the user knows how to restart everything and the developer
> has core dumps to look at. (to see which program/thread holds the lock and would not give it
> up).
>
> Any thoughts on this?
>
> K.O. |