C++ standard thread class?
I have come across many ad hoc implementations of thread class in C++, but why is there no standard library thread class like the one in Java? The one that I generally use in C++ i开发者_运维问答s http://www.linuxdocs.org/HOWTOs/C++Programming-HOWTO-24.html
std::thread
will be standardized in C++0x, and many compilers already support it.
It is perhaps more ambitious than your cited example as construction/destruction signifies initiation/joining of thread execution.
Here's another article.
Until C++0x arrives, I recommend using the Boost Thread class, which is about as close to a standard as we have for the kind of Thread class you're after.
C++ was invented in 1979. I don't think the notion of threads was really widespread at that time. (While there were multi-user and multi-process OSes back then, they were all very peculiar in their own ways. For example, it took until 1995 for pthreads to be standardised.)
For some more info on how to use std::thread see ...
std::threadhttp://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html
You might want to do a test with your compiler to see if it supports it. If not until then use one of the other libs.
精彩评论