[Solved] Why iterators are not a solution for CuncurentModificationException?

From https://docs.oracle.com/javase/7/docs/api/java/util/ConcurrentModificationException.html For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it. In general, the results of the iteration are undefined under these circumstances. Some Iterator implementations (including those of all the general purpose collection implementations provided by the JRE) may choose to throw … Read more

[Solved] Permanent Threads in QT

You should use Qt signaling mechanism. class QWindow : QMainWindow { //this macro is important for QMake to let the meta programming mechanism know //this class uses Qt signalling Q_OBJECT slots: void updateLabel(QString withWhat) … }; And now You just need to connect this slot to some signal class SomeThreadClass : QObject { Q_OBJECT … … Read more

[Solved] Convert a process based program into a thread based version?

The general case depends on whether the threads are wholly independent of each other. If you go multi-threaded, you must ensure that any shared resource is accessed appropriate protection. The code shown has a shared resource in the use of srand() and rand(). You will get different results in a multi-threaded process compared with those … Read more

[Solved] Should a class be thread-safe? [closed]

As a general rule, it’s more flexible to leave it to the user. For example, consider a map-type container. Suppose the application needs to atomically move something from one map to another map. In this case, the user needs to lock both maps before the insert-erase sequence. Having such a scenario be automatically taken care … Read more

[Solved] When will objects allocated on a thread be freed after the thread completes? [closed]

The simple answer is eventually: no sooner, no later. You have no direct control over when garbage will be collected. Provided the instance has no more references to it, the garbage collector will clean it up at some point. 4 solved When will objects allocated on a thread be freed after the thread completes? [closed]

[Solved] Is CRITICAL SECTION required? [closed]

A CRITICAL_SECTION is a simple sync mechanism for multi-threaded. You use a CRITICAL_SECTION to protect a block of code from having two or more threads running it at the same time. You will not see a difference, with or without in most cases, it is there to protected shared resources from getting run over for … Read more

[Solved] C++ Threading Error

The issue: you are calling join method for empty thread – you cannot do this, when you call join on non-joinable thread you will get exception. In this line thread threads[MAX_THREADS]; you created MAX_THREADS threads using its default constructor. Each thread object after calling default ctor is in non-joinable state. Before calling join you should … Read more

[Solved] merge paint results in thread bitmap painting

bitblt(Masterbitmap.Canvas.handle, 0, 0, XPixel, YPixel, bitmap.Canvas.handle, 0, 0, srcand); you explicitly called Masterbitmap.Canvas.Lock, however you didn’t call bitmap.Canvas.Lock (so you can loose the canvas handle anytime within this call…) Additionally, you need to consider thread safety within GDI itself: Sharing of any GDI objects between different threads should be avoided at all cost. For example … Read more