Pregunta

I have a few questions about the library Loki and also the new standard C++11.

My first question is about the LevelMutex functionality of the library. LevelMutex directly uses a CRITICAL_SECTION on windows and a pthread_mutex_t in Linux in order the implement the functionalities. The classes are extremely well design but a question remains in my head. Now that we have a brand new wrapper in the new standard (std::mutex) is it worth replacing the low level objects that are platform dependent by this one ? If not, why ? My point is that - we can remove lots of compiler check in Loki - we can keep an up to date version of Loki and all changes will be pushed to Loki when changes occur in the standard library - we can use the exceptions of std::mutex in Loki.

I know that std::mutex is just a wrapper around the platforms mutex objects and that the exceptions are also a wrapper around the system specific errors but still ... The same question applies for the functionalities in Threads.h.

My second question is about the SmartPtr implemented in Loki. Do you think it is worth using this implementation given the fact that we have shared_ptr, unique_ptr, etc ? If so why ? If not, I think it a good idea to rewrite the LockingPtr implementation a little bit to get a thread safe shared_ptr ?

My last question is about the new std::thread functionality in the C++11 standard. I am thinking of writing policy classes for this particular functionality like having the ability to create joinable threads or detachable threads. In your opinion, what part of std::thread would be interesting to create a policy for ?

Thanks in advance for the answers !

¿Fue útil?

Solución

It's a broad and somewhat subjective topic and I can only give you my personal advice. I won't go into details as I think it's important to take a step back and look at the bigger picture.

I made some good experience by using the new C++11 standard and replacing other libraries by whatever the standard library offers. And by "me", I also mean the code base of where I work (a department of a company with more than 100.000 employees).

Libraries like Loki or Boost have done a pretty good job of exploring new frontiers and bringing C++ forward, for Boost it was actually an explicit goal to create new components which would eventually be standardized.

While the standardized versions of std::shared_ptr, std::thread and std::mutex might lack a few details, they are well designed, portable and, given that they are part of the standard library shipping with the compiler, they are very well tested! These are important points in favor of them. It also helps to make your code future proof and easier to maintain, it's easier for new people to jump in.

My advice would thus be this: Use everything C++11 (including the standard library) has to offer as much as possible. Only use Loki, Boost or other libraries if necessary but keep your mind open by following their development.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top