multithreading

code crash after opening a QfileDialog in a QThread

左心房为你撑大大i 提交于 2020-12-12 06:27:34
问题 I wrote a code who display in a GUI, the steps of calcul of an algorithm. For this, i use a QThread which is in charge to check the steps and display it in a GUI. This alone is working. However, the first step for the user is to select a configuration file with a QFileDialog. And at this level, Python code crashes after the openning of the QFileDialog if a file is not selected after several seconds. The crash occures when the mouse goes over the QFileDialog window openned. I quite new with

code crash after opening a QfileDialog in a QThread

孤街浪徒 提交于 2020-12-12 06:26:28
问题 I wrote a code who display in a GUI, the steps of calcul of an algorithm. For this, i use a QThread which is in charge to check the steps and display it in a GUI. This alone is working. However, the first step for the user is to select a configuration file with a QFileDialog. And at this level, Python code crashes after the openning of the QFileDialog if a file is not selected after several seconds. The crash occures when the mouse goes over the QFileDialog window openned. I quite new with

Can a single core processor still throw ConcurrentModificationException?

◇◆丶佛笑我妖孽 提交于 2020-12-12 05:57:47
问题 If I spawn 2 threads on a single core PC does it ever access for example an ArrayList in the same time so it will throw ConcurrentModificationException ? My gut tells me although there are 2 threads, they cannot achieve true parallelism because there is a single core and what it can do mostly is to jump from one thread to another but without executing an instruction such as arrayList.add(element) in the same time. 回答1: TL;DR: Yes List<String> myList = new ArrayList<String>(Arrays.asList("My

Can a single core processor still throw ConcurrentModificationException?

你。 提交于 2020-12-12 05:57:26
问题 If I spawn 2 threads on a single core PC does it ever access for example an ArrayList in the same time so it will throw ConcurrentModificationException ? My gut tells me although there are 2 threads, they cannot achieve true parallelism because there is a single core and what it can do mostly is to jump from one thread to another but without executing an instruction such as arrayList.add(element) in the same time. 回答1: TL;DR: Yes List<String> myList = new ArrayList<String>(Arrays.asList("My

Can a single core processor still throw ConcurrentModificationException?

我的梦境 提交于 2020-12-12 05:56:47
问题 If I spawn 2 threads on a single core PC does it ever access for example an ArrayList in the same time so it will throw ConcurrentModificationException ? My gut tells me although there are 2 threads, they cannot achieve true parallelism because there is a single core and what it can do mostly is to jump from one thread to another but without executing an instruction such as arrayList.add(element) in the same time. 回答1: TL;DR: Yes List<String> myList = new ArrayList<String>(Arrays.asList("My

Can a single core processor still throw ConcurrentModificationException?

末鹿安然 提交于 2020-12-12 05:56:46
问题 If I spawn 2 threads on a single core PC does it ever access for example an ArrayList in the same time so it will throw ConcurrentModificationException ? My gut tells me although there are 2 threads, they cannot achieve true parallelism because there is a single core and what it can do mostly is to jump from one thread to another but without executing an instruction such as arrayList.add(element) in the same time. 回答1: TL;DR: Yes List<String> myList = new ArrayList<String>(Arrays.asList("My

Can I create widgets on a non-GUI thread, then send to the GUI?

对着背影说爱祢 提交于 2020-12-12 02:56:29
问题 I have a complex function in my MainWindow class which periodically runs queries and changes attributes and data of the widgets. Since it can take a long time on the main thread, the GUI can appear to freeze. So I created a GUIUpdater class on another thread to do the periodic operation. I based it on the solution here, which shows how to update a QLabel from another thread: Qt - updating main window with second thread But that solution requires defining a connection. With a complex function

Ruby MRI 1.8.7 - File writing thread safety

半城伤御伤魂 提交于 2020-12-10 07:57:10
问题 It seems to me that file writing in Ruby MRI 1.8.7 is completely thread safe. Example 1 - Flawless Results: File.open("test.txt", "a") { |f| threads = [] 1_000_000.times do |n| threads << Thread.new do f << "#{n}content\n" end end threads.each { |t| t.join } } Example 2 - Flawless Results (but slower): threads = [] 100_000.times do |n| threads << Thread.new do File.open("test2.txt", "a") { |f| f << "#{n}content\n" } end end threads.each { |t| t.join } So, I couldn't reconstruct a scenario

Ruby MRI 1.8.7 - File writing thread safety

大城市里の小女人 提交于 2020-12-10 07:57:08
问题 It seems to me that file writing in Ruby MRI 1.8.7 is completely thread safe. Example 1 - Flawless Results: File.open("test.txt", "a") { |f| threads = [] 1_000_000.times do |n| threads << Thread.new do f << "#{n}content\n" end end threads.each { |t| t.join } } Example 2 - Flawless Results (but slower): threads = [] 100_000.times do |n| threads << Thread.new do File.open("test2.txt", "a") { |f| f << "#{n}content\n" } end end threads.each { |t| t.join } So, I couldn't reconstruct a scenario

std::lock_guard() for a locked std::mutex

醉酒当歌 提交于 2020-12-10 06:48:07
问题 I am new to C++11 threading. The following piece of code should be executed only by the first thread. The other threads (which might race with the first thread) should not enter the locked code area (that's why the std::try_lock() is there). std::mutex mutex; // now ensure this will get called only once per event if (std::try_lock(_mutex) != -1) { return; } { std::lock_guard<std::mutex> guard(_mutex); // critical section } // mutex will be unlocked here (Outside from writing my own lock_guard