开发者

Question about QThread implementation

A 开发者_Python百科QThread object represents a single thread of execution. But is the OS thread created when the QThread object is created, or when the start() method is called?

I'm interested in whether I can have several QThread objects lying around, and the OS will create threads on start() and kill them after run() returns, and then I can reuse the QThread objects again. But I don't want to hold OS resources while the QThread objects are not doing anything.

(for the record, I'm aware of QtConcurrent and the QThreadPool, and no, they don't satisfy my needs in this situation)


In Linux the thread object is created (via pthread_create) during the QThread::start method. It looks about the same with Windows.

You can see the source here:

Unix: http://qt.gitorious.org/qt/qt/blobs/master/src/corelib/thread/qthread_unix.cpp (line 542).

Windows: http://qt.gitorious.org/qt/qt/blobs/master/src/corelib/thread/qthread_win.cpp (line 419).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜