That's because the consumer and producer threads outlive the main thread (your program terminates immediately after thread creation).
Try, for instance:
#include <iostream>
#include <thread>
class produceconsume
{
public:
produceconsume(){}
virtual ~produceconsume(){}
std::thread producer()
{
return std::thread(&produceconsume::producerth, this);
}
std::thread consumer()
{
return std::thread(&produceconsume::consumerth, this);
}
void producerth();
void consumerth();
void run();
private:
};
void produceconsume::producerth()
{
while (true) {}
}
void produceconsume::consumerth()
{
while (true) {}
}
void produceconsume::run()
{
auto tp = producer();
auto tc = consumer();
tc.join();
tp.join();
}