concurrency

Queue print jobs in a separate single Thread for JavaFX

主宰稳场 提交于 2020-01-05 04:31:12
问题 currently I am experimenting with Concurrency in Java/JavaFX. Printing must run in a different thread otherwise it will make the JavaFX main thread freeze for a couple seconds. Right now my printing is done with this simplified example. public void print(PrintContent pt) { setPrintContent(pt); Thread thread = new Thread(this); thread.start(); } @Override public void run() { // send content to printer } With this code I am sending many print jobs parallel to my printer. Therefore I get the

How to implement search in file system in haskell?

。_饼干妹妹 提交于 2020-01-04 23:45:47
问题 I'm not exactly new to haskell, but haven't used it much in real world. So what I want to do is to find all git repositories starting from some folders. Basically I'm trying to do this find . -type d -exec test -e '{}/.git' ';' -print -prune only faster via using haskell concurrency features. This is what I got so far. import Control.Concurrent.Async import System.Directory (doesDirectoryExist) import System.FilePath ((</>)) import System.IO (FilePath) isGitRepo :: FilePath -> IO Bool

How to calculate Amadahl's Law for threading effectiveness

天涯浪子 提交于 2020-01-04 09:35:28
问题 Its easy to find and understand the function definition for Amadahl's Law, but all of the working examples I was able to find were either too vague or too academic/cerebreal for my tiny pea brain to understand. Amadahl's Law takes to parameters: F , the % of a task that cannot be improved via multi-threading, and N , the number of threads to use. How does one calculate F with any degree of accuracy? How do you look at a piece of code and determine whether that will be improved by multi

Java : threaded serial port read with Java.util.concurrent thread access

喜欢而已 提交于 2020-01-04 09:04:24
问题 I'm trying to write a Java serial device driver and want to use the (new to me) java.util.concurrent package. I have one method which sends a packet then waits for an ACK. I plan to have char. reception run in a different thread. If the receive thread gets an ACK it should notify the thread with the send packet function. The receive thread implements a state machine and should notify any listeners of decoded packets. I think I know how to do this using direct Threads, wait , notify etc., but

Monitor concurrency (sharing object across processes) in Python

怎甘沉沦 提交于 2020-01-04 07:26:08
问题 I'm new here and I'm Italian (forgive me if my English is not so good). I am a computer science student and I am working on a concurrent program project in Python. We should use monitors, a class with its methods and data (such as condition variables). An instance (object) of this class monitor should be shared accross all processes we have (created by os.fork o by multiprocessing module) but we don't know how to do. It is simpler with threads because they already share memory but we MUST use

ThreadLocal SimpleDateFormat in an Enum?

≯℡__Kan透↙ 提交于 2020-01-04 06:08:58
问题 I am doing some refactoring of our date formatting code because we've managed to introduce numerous inconsistencies for various reasons. I understand that it's best to have a ThreadLocal SimpleDateFormat . After discussing here we are unsure if ThreadLocal is even required when using in an Enum because we never change the instance and don't expose it so it can't be mutated? if it is still required does being an Enum, like this, break anything? Is anything else broken or not doing what I think

Multiprocessing HTTP get requests in Python

a 夏天 提交于 2020-01-04 05:06:08
问题 I have to make numerous (thousands) of HTTP GET requests to a great deal of websites. This is pretty slow, for reasons that some websites may not respond (or take long to do so), while others time out. As I need as many responses as I can get, setting a small timeout (3-5 seconds) is not in my favour. I have yet to do any kind of multiprocessing or multi-threading in Python, and I've been reading the documentation for a good while. Here's what I have so far: import requests from bs4 import

Is there a tool to determine whether a program is “correctly synchronized” as defined in JLS?

流过昼夜 提交于 2020-01-04 04:19:32
问题 The Java Language Specification 7 (JLS7-17.4.5) defines a "correctly synchronized" program like this: "A program is correctly synchronized if and only if all sequentially consistent executions are free of data races". JLS7-17.4.5 also states that: Without correct synchronization, very strange, confusing and counterintuitive behaviors are possible. So, from a programmer's point of view, it would be very useful to have a tool to determine whether a program is "correctly synchronized" according

ProcessPoolExecutor, BrokenProcessPool handling

半腔热情 提交于 2020-01-04 03:19:33
问题 In this documentation ( https://pymotw.com/3/concurrent.futures/ ) it says: "The ProcessPoolExecutor works in the same way as ThreadPoolExecutor, but uses processes instead of threads. This allows CPU-intensive operations to use a separate CPU and not be blocked by the CPython interpreter’s global interpreter lock." This sounds great! It also says: "If something happens to one of the worker processes to cause it to exit unexpectedly, the ProcessPoolExecutor is considered “broken” and will no

Object locking private class members - best practice? (Java)

我怕爱的太早我们不能终老 提交于 2020-01-04 02:32:10
问题 I asked a similar question the other day but wasn't satisfied with the response, mainly because the code I supplied had some issues that people focused on. Basically, what is the best practice for locking private members in Java? Assuming each private field can only be manipulated in isolation and never together (like in my Test class example below), should you lock each private field directly (example 1), or should you use a general lock object per private field you wish to lock (example 2)?