//QT线程
#include <QtGui/QtGui>
QMutex mutex;
int count = 0;
class MyThread : public QThread
{
public:
virtual void run();
};
void MyThread::run()
{
int i=10000;
while(i--)
{
mutex.lock();
count++;
qDebug( "at %p count:%d",this,count );
//msleep(100);
mutex.unlock();
}
}
int main()
{
MyThread a;
MyThread b;
a.start();
b.start();
a.wait();
b.wait();
//如果不加锁,得到的count可能不正确.
qDebug( "count:%d",count );
return 0;
}