views:

130

answers:

1

I'm trying to write a library to separate all the disk activity out into its own thread, but the documentation doesn't really care about such things.

What I want to accomplish is that aside from startup, all disk activity is asynchronous, and for that, I need to wrap every class that accesses the disk. Here's what I found so far:

QtCore:

QtGui:

I'm sure there are more.

+1  A: 

I have a couple of points -

First, when you do this, remember that all GUI objects are based on QWidget, have run in the start-up thread. See http://doc.trolltech.com/4.6/threads-qobject.html which talks about threading. The quote is "Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread".

This also means that if you need to display information from one of these wrapper classes on the screen, you need to be careful about ownership of objects when you pass information back to the GUI thread. Particularly, anything that is based on QObject.

Second, starting threads carries a run-time cost. So I would suggest that you structure your design to minimize the number of times this wrapper thread class is created and destroyed.

Overall an interesting approach to files. This is one that I'm going to consider for my current application. It may solve some problems I'm having.

photo_tom
The idea is to have a singleton that dispatches requests to the appropriate (private) thread - I'm planning one thread per physical disk. Since the thread is primarily sleeping and waiting, I don't think it's going to hurt to leave it around.
Jurily
That would work. What I was trying to point was that if you were going to create this thread every time you needed it, there would be a run-time cost. I really like the singleton idea and am going to look at including it in my project tomorrow.
photo_tom