Skip to content

Instantly share code, notes, and snippets.

@RoyBellingan
Last active March 19, 2016 23:29
Show Gist options
  • Save RoyBellingan/3afebad0c57b21ae5661 to your computer and use it in GitHub Desktop.
Save RoyBellingan/3afebad0c57b21ae5661 to your computer and use it in GitHub Desktop.
Small demo to crash
#include <QMap>
#include <QMapIterator>
#include <thread>
#include <QMutex>
QMap<int,QMap<QByteArray,QByteArray>> me;
QMap<QByteArray,QByteArray> row;
QMutex mutex;
void blaxx(){
while(true){
for (int i = 0; i < 200;) {
mutex.lock();
me.insert(i,row);
mutex.unlock();
i=i+5;
}
}
}
int main(){
row.insert("srly","lol");
std::thread th[1];
th[0] = std::thread(blaxx);
mutex.lock();
me.insert(10,row);
mutex.unlock();
while(true){
int k=4;
QMap<int,QMap<QByteArray,QByteArray>>::iterator iter = me.begin();
while(iter != me.end()){
k = k + 5;
QString dbname = iter.value().value("blablabla");
mutex.lock();
me.insert(k,row);
iter = me.erase(iter);
mutex.unlock();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment