multithreading

Drawing to main form canvas from a non-main thread

a 夏天 提交于 2020-02-24 16:57:25
问题 I am trying to make an arcade game for my school project. The basic idea is to do all the math and drawing in other thread than the main, and to use the main thread only for input routines. Drawing is done by a procedure saved in an external unit, and is done by creating a bitmap, then drawing parts of the environment on the bitmap and finally dawing the bitmap on the main form's canvas. When I finished the drawing procedure, I tried to run it from the main thread, and managed to make

display UIAlert will crash the app on present?

≡放荡痞女 提交于 2020-02-24 11:40:26
问题 I have a test connection action logic. it will test the server in live or not. the bug happens when the logic finishes the test and try display UIAlertController inside closure thread it will crash the systems. @IBAction func TestNetwork(_ sender: Any) { var message = "\(internetConnection) internet connection \n \(serverStatus) server\n " self.showSpinner(onView: self.view) DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { self.testConnection(connectionTestCompletionHanlder:

Unmarshalling Hangs on Open Socket

坚强是说给别人听的谎言 提交于 2020-02-24 11:14:26
问题 I've written a runnable network class that listens on a socket and unmarshalls the input. It also can write to the socket with a marshalled object. An issue arises because the socket remains open (in order to allow later communication between client and host) - this causes the unmarshalling of the input stream to hang. I've tried writing XMLStreamConstants.END_DOCUMENT from the sender side but this causes an error unmarshalling instead of hanging. Here's some of the code for the network class

What happens to expected memory semantics (such as read after write) when a thread is scheduled on a different CPU core?

 ̄綄美尐妖づ 提交于 2020-02-24 11:13:30
问题 Code within a single thread has certain memory guarantees, such as read after write (i.e. writing some value to a memory location, then reading it back should give the value you wrote). What happens to such memory guarantees if a thread is rescheduled to execute on a different CPU core? Say a thread writes 10 to memory location X, then gets rescheduled to a different core. That core's L1 cache might have a different value for X (from another thread that was executing on that core previously),

If I want to give more work to my Process Pool, can I call Pool.join() before Pool.close()?

余生长醉 提交于 2020-02-24 06:53:59
问题 The documentation for multiprocessing states the following about Pool.join() : Wait for the worker processes to exit. One must call close() or terminate() before using join() . I know that Pool.close() prevents any other task from being submitted to the pool; and that Pool.join() waits for the pool to finish before proceeding with the parent process. So, why can I not call Pool.join() before Pool.close() in the case when I want to reuse my pool for performing multiple tasks and then finally

If I want to give more work to my Process Pool, can I call Pool.join() before Pool.close()?

南楼画角 提交于 2020-02-24 06:45:05
问题 The documentation for multiprocessing states the following about Pool.join() : Wait for the worker processes to exit. One must call close() or terminate() before using join() . I know that Pool.close() prevents any other task from being submitted to the pool; and that Pool.join() waits for the pool to finish before proceeding with the parent process. So, why can I not call Pool.join() before Pool.close() in the case when I want to reuse my pool for performing multiple tasks and then finally

Computing Sums Using Multithreading

爷,独闯天下 提交于 2020-02-24 03:55:22
问题 I am working on a program that is to take the input of 15,000 integers from a file. After reading the values, the thread should then create 10 threads with each thread responsible for computing the sum of their block (1,500 values each). Each thread will then print the sum of its values, and the main thread will compute the sum from all 10 threads. What I have is mind is to read in all values and store them in an int array while using an int to keep count of the number of values read (let's

When is a WebView ready for a snapshot()?

你说的曾经没有我的故事 提交于 2020-02-23 09:49:06
问题 The JavaFX docs state that a WebView is ready when Worker.State.SUCCEEDED is reached however, unless you wait a while (i.e. Animation , Transition , PauseTransition , etc.), a blank page is rendered. This suggests that there is an event which occurs inside the WebView readying it for a capture, but what is it? There's over 7,000 code snippets on GitHub which use SwingFXUtils.fromFXImage but most of them appear to be either unrelated to WebView , are interactive (human masks the race condition

Threading in a Windows Service

别说谁变了你拦得住时间么 提交于 2020-02-23 08:28:11
问题 I've created an app which uses Observable Lists. I've made the ObservableList class threadsafe (I think) and it's working fine now in my application. Now I'm trying to install my application as a service. This works fine as well, up untill the point something gets added to the list. I think the thread there just dies. I've got the following code: /// <summary> /// Creates a new empty ObservableList of the provided type. /// </summary> public ObservableList() { //Assign the current Dispatcher

Kivy and Flask threads blocking each other in Python2

二次信任 提交于 2020-02-23 07:24:05
问题 I have the following setup: Kivy 1.11.1, Flask 1.1.1 and Python 2.7.13. I want to fetch a JSON request but I am stuck at Flask app does not fetch requests while the Kivy GUI is running. Even when run in separate threads they block each other. The main api script eg_api.py: #!/usr/bin/python2.7 python2.7 # -*- coding: utf-8 -*- # kivy modules first, if not Kivy may cause problems import kivy from kivy.app import App from kivy.lang import Builder from kivy.uix.label import Label from kivy.uix