Originally Posted by
javimoya
wysota... do you know an EASY book or website to start learning about threads and pararell programming (basic concepts)? it's focused on Qt it would be nice.
Well... Silbershatz's book on operating systems is a classic. Besides that I don't know any such resources. In my opinion my Qt Quarterly article filled some of the gaps regarding Qt perfectly when it comes to practical approach to SIMD. If you need something specific then say so, I can try to do some research and write more about it. But basically it takes a lot of thinking and practice to understand threading and parallel programming on a decent level. You can look for articles on "grid computing" (or cloud computing), that's a popular subject nowadays and there are a lot of conferences dedicated to it, like this one: http://www.ppam.pl/ to just name the one I participated in (and it helped start my interest in parallel programming). The basic thing you should undestand is how processes in your OS work, then you can learn about threads and synchronization and then you can focus on more high-level aspects like parallel programming, SIMD and stuff like that. OpenCL or equivalent should then follow if you want a many-core (note, not "multi-core") solutions.
Oh, and good computer science studies also help a lot
Originally Posted by
chezifresh
Good link. Aside from some details, that describes basically what my thumbnailing service does.
The main difference is that the solution described in the article adjusts to your machine and is more high-level.
The problem I ran into was that my thumbnailing service sometimes produces thumbnails so fast that the UI thread is swamped with repaint events, and causes the UI to become unresponsive.
There is an easy solution - process the data you receive in batches. The simplest way is to use a timer, like so:
void MyModel
::newImageReady(const QImage &img
) { if(!m_batchTimer.isActive()) m_batchTimer.start(1000); // timer is single shot
m_pending << img;
if(m_pending.size()>=10) {
// force update when 10 images are waiting
m_batchTimer.stop();
batchTimerTimeout();
}
}
void MyModel::batchTimerTimeout() {
int minRow = rowCount(), maxRow = -1;
foreach
(const QImage &img, m_pending
) { minRow = qMin(minRow, idx.row());
maxRow = qMax(maxRow, idx.row());
m_data[idx.row()].pixmap = px;
}
m_pending.clear();
emit dataChanged(index(minRow, 0), index(maxRow, columnCount()-1));
}
void MyModel::newImageReady(const QImage &img) {
if(!m_batchTimer.isActive()) m_batchTimer.start(1000); // timer is single shot
m_pending << img;
if(m_pending.size()>=10) {
// force update when 10 images are waiting
m_batchTimer.stop();
batchTimerTimeout();
}
}
void MyModel::batchTimerTimeout() {
int minRow = rowCount(), maxRow = -1;
foreach(const QImage &img, m_pending) {
QModelIndex idx = indexFromText(img.text("index"));
minRow = qMin(minRow, idx.row());
maxRow = qMax(maxRow, idx.row());
QPixmap px = QPixmap::fromImage(img);
m_data[idx.row()].pixmap = px;
}
m_pending.clear();
emit dataChanged(index(minRow, 0), index(maxRow, columnCount()-1));
}
To copy to clipboard, switch view to plain text mode
The way I approached this was to have my thumbnail scaling/loading threads emit a signal with the QImage it generated. The thumbnail service adds that thumbnail to a queue of thumbnails that need to be dispatched. Then it waits for a timer to go off. The timeout() signal is connected to a slot that dispatches the thumbnails:
I should really read posts to the end before answering them Yeah, good approach but mine is better - queue in the model, not in the service, worker threads can't create pixmaps.
Bookmarks