#include <QThread>
#include <QTimerEvent>
+#include <iostream>
+
class DrawingWindow::DrawingThread: public QThread {
public:
DrawingThread(DrawingWindow &w, ThreadFunction f)
void run()
{
- exit(threadFunction(drawingWindow));
+ threadFunction(drawingWindow);
}
private:
thread = new DrawingThread(*this, fun);
thread_started = false;
+
+ mutex_enabled = true;
}
DrawingWindow::~DrawingWindow()
{
+ mutex.lock();
+ mutex_enabled = false;
+ mutex.unlock();
+ std::cerr << "A\n";
+ thread->terminate();
+ std::cerr << "B\n";
+ thread->wait();
+ std::cerr << "C\n";
delete thread;
delete painter;
delete image;
+ std::cerr << "D\n";
}
void DrawingWindow::setColor(const QColor &color)
/* Q_OBJECT */
public:
- typedef int (*ThreadFunction)(DrawingWindow &);
+ typedef void (*ThreadFunction)(DrawingWindow &);
static const int DEFAULT_WIDTH = 640;
static const int DEFAULT_HEIGHT = 480;
bool dirtyFlag;
QRect dirtyRect;
+ bool mutex_enabled;
QMutex mutex;
void initialize(ThreadFunction fun, int width, int height);
inline
void DrawingWindow::lock()
{
- mutex.lock();
+ if (mutex_enabled)
+ mutex.lock();
+ if (!mutex_enabled)
+ mutex.unlock();
}
inline
#include <iostream>
-int flip(DrawingWindow &w)
+void flip(DrawingWindow &w)
{
std::cout << "[ " << w.width() << " x " << w.height() << " ]\n";
// << y << " (" << c << ")\n";
}
}
- return 0;
}
-int mandel(DrawingWindow &w)
+void mandel(DrawingWindow &w)
{
/* paramètres par défaut */
int larg = w.width();
}
cr += pr;
}
- return 0;
}
-int lines(DrawingWindow &w)
+void lines(DrawingWindow &w)
{
int n = 100000;
int xmax = w.width();
w.setColor(r, g, b);
w.drawLine(x1, y1, x2, y2);
}
- return 0;
}
int main(int argc, char *argv[])