multithreading

Why Java parallel file writing is not working?

坚强是说给别人听的谎言 提交于 2020-08-20 08:53:10
问题 I am trying to write a script that will run a .exe program 4 times with different parameters. I created one thread for each .exe run. Each thread will write an output file. My problem is that, it should write in parallel, but as you can you see on the screenshot below, the file write one after another. How should this be resolved? Here's the main method: public static void main (String args[]) { ExecutorService executor = Executors.newFixedThreadPool(4); executor.execute(new RunnableReader(

Python code not continuing execution after thread started

爱⌒轻易说出口 提交于 2020-08-20 06:13:33
问题 I am writing a threaded Python script for the first time and running into some trouble. The general idea is that a Raspberry Pi receives data from a Bluetooth connection, this data is then used to create a thread that calls the start_laps method. Once this thread is started, I need to continue listening for new data to determine if the thread should be killed. However, my code is not continuing execution after the thread is started. What would cause this? import json import bluetooth import

Why do I get an error that “Sync is not satisfied” when moving self, which contains an Arc, into a new thread?

匆匆过客 提交于 2020-08-19 16:55:07
问题 I have a struct which holds an Arc<Receiver<f32>> and I'm trying to add a method which takes ownership of self , and moves the ownership into a new thread and starts it. However, I'm getting the error error[E0277]: the trait bound `std::sync::mpsc::Receiver<f32>: std::marker::Sync` is not satisfied --> src/main.rs:19:9 | 19 | thread::spawn(move || { | ^^^^^^^^^^^^^ `std::sync::mpsc::Receiver<f32>` cannot be shared between threads safely | = help: the trait `std::marker::Sync` is not

Creating new thread with method with parameter [duplicate]

一曲冷凌霜 提交于 2020-08-19 02:53:06
问题 This question already has answers here : c# thread method (5 answers) Closed 7 years ago . I am trying to create new thread and pass a method with parameter,but errors out. Thread t = new Thread(myMethod); t.Start(myGrid); public void myMethod(UltraGrid myGrid) { } ---------errors------------ Error: CS1502 - line 92 (164) - The best overloaded method match for ' System.Threading.Thread.Thread(System.Threading.ThreadStart) ' has some invalid arguments Error: CS1503 - line 92 (164) - Argument

switching between threads in Intellij Idea

旧巷老猫 提交于 2020-08-17 03:33:39
问题 How to switch between threads of a suspended program? or Any tutorial on multi-threaded debugging with Intellij Idea describing basic features - suspend, resume, switch between threads. very good tutorials/step-by-step guide available for Netbeans: e.g. https://netbeans.org/kb/docs/java/debug-multithreaded.html 回答1: Trick is to set breakpoint suspend policy to - Thread. View breakpoint properties (right-click on breakpoint) Once done threads will hit breakpoint and block, now active thread

How threads are executed in the memory?

*爱你&永不变心* 提交于 2020-08-15 12:17:48
问题 I am learning about Thread in Java . I was tring to fetch which thread is running. But, I am not able to understand the order of the output. Following is my code public class practice extends Thread { public void run(){ for(int i=1;i<4;i++){ System.out.println(i); System.out.println(Thread.currentThread().getName()); } } public static void main(String[] args) { practice t1=new practice(); practice t2=new practice(); practice t3=new practice(); t1.start(); t2.start(); t3.start(); } } Output: 1

Call an unmanaged dll always from same thread in C#

谁说我不能喝 提交于 2020-08-10 20:44:32
问题 What is the easiest way to call functions in an unmanaged dll from c#, always from the same thread? My problem: I have to use an unmanaged dll. This dll is not thread-safe and additionaly it has UI included that expects (like WPF) to be used always by the same thread. So it seems it regards the first thread that affects UI in the dll as its "main" thread. The "not thread-safe" problem I think would be resolved by using a semaphore. The "only from main thread" problem can be easily avoided by

Call an unmanaged dll always from same thread in C#

五迷三道 提交于 2020-08-10 20:44:11
问题 What is the easiest way to call functions in an unmanaged dll from c#, always from the same thread? My problem: I have to use an unmanaged dll. This dll is not thread-safe and additionaly it has UI included that expects (like WPF) to be used always by the same thread. So it seems it regards the first thread that affects UI in the dll as its "main" thread. The "not thread-safe" problem I think would be resolved by using a semaphore. The "only from main thread" problem can be easily avoided by

Why isnt Send implemented for a struct containing Arc?

こ雲淡風輕ζ 提交于 2020-08-10 20:13:09
问题 I'm using a crate to interact with Postgres with simply writing sql queries by hands (Diesel seems for my simple case) and got stuck about the multithreaded access to the database client. Here is the code: use postgres::Client; pub struct Database{ connection: Arc<Client> } impl Database { pub fn from_config(url: &str) -> Database { //... } } fn main() { let url: String = //... let db = db::Database::from_config(&url); let db_ref = Arc::new(db); consume(future(Arc::clone(&db_ref))); // <-----

Updated code of NullPointerException problem with ConcurrentHashMap

久未见 提交于 2020-08-10 20:12:10
问题 I am trying to do a multi thread simulator where there are workers (threads) and jobs to solve, so every thread has to solve a job and start to solve the next in order, the integer of the job is the time in seconds that is required to solve the job, this is a simulation so the code prints the index of the thread with the initialization time of the job but it hasn't to be sleeping that number of seconds. The problem is that i'm getting a NullPointerException only when there are a lot of jobs