multithreading

Can you specify a non-static lifetime for threads? [duplicate]

天大地大妈咪最大 提交于 2021-02-05 09:14:07
问题 This question already has answers here : How can I pass a reference to a stack variable to a thread? (1 answer) Thread references require static lifetime? (1 answer) How do I use static lifetimes with threads? (2 answers) How can I send non-static data to a thread in Rust and is it needed in this example? (1 answer) Closed 1 year ago . Here's a toy example of my problem: use std::sync::{Arc, Mutex}; fn operate_in_chunks(vec: &mut Vec<f32>) { let chunk_size = 10; let mutex_vec: Arc<Mutex<&mut

Race conditions when adding to, but not reading from, a List<T> (or Stack or Queue) - what happens?

邮差的信 提交于 2021-02-05 09:13:25
问题 Note: I'm asking this question relative to the 3.5 framework, so I'm not including any of the newer multithreaded constructs in 4.0 (which I'm still learning). I've been trying to come up with an answer on this to try and close out an argument I've been having, but I don't feel like I've found a conclusive description as to what would or could happen in the following scenario. Say you have an app with multiple threads that are all generating objects, with each thread generating a unique

Race conditions when adding to, but not reading from, a List<T> (or Stack or Queue) - what happens?

不打扰是莪最后的温柔 提交于 2021-02-05 09:11:36
问题 Note: I'm asking this question relative to the 3.5 framework, so I'm not including any of the newer multithreaded constructs in 4.0 (which I'm still learning). I've been trying to come up with an answer on this to try and close out an argument I've been having, but I don't feel like I've found a conclusive description as to what would or could happen in the following scenario. Say you have an app with multiple threads that are all generating objects, with each thread generating a unique

Increase Number of running thread in Parallel.For

我的未来我决定 提交于 2021-02-05 08:52:07
问题 I have just did a sample for multithreading using This Link like below: Console.WriteLine("Number of Threads: {0}", System.Diagnostics.Process.GetCurrentProcess().Threads.Count); int count = 0; Parallel.For(0, 50000, options,(i, state) => { count++; }); Console.WriteLine("Number of Threads: {0}", System.Diagnostics.Process.GetCurrentProcess().Threads.Count); Console.ReadKey(); It gives me 15 thread before Parellel.For and after it gives me 17 thread only. So only 2 thread is occupy with

OpenMP in C array reduction / parallelize the code

纵然是瞬间 提交于 2021-02-05 08:49:46
问题 I have a problem with my code, it should print number of appearances of a certain number. I want parallelize this code with OpenMP, and I tried to use reduction for arrays but it's obviously didn't working as I wanted. The error is: "segmentation fault". Should some variables be private? or it's the problem with the way I'm trying to use the reduction? I think each thread should count some part of array, and then merge it somehow. #pragma omp parallel for reduction (+: reasult[:i]) for (i = 0

OpenMP in C array reduction / parallelize the code

烈酒焚心 提交于 2021-02-05 08:49:26
问题 I have a problem with my code, it should print number of appearances of a certain number. I want parallelize this code with OpenMP, and I tried to use reduction for arrays but it's obviously didn't working as I wanted. The error is: "segmentation fault". Should some variables be private? or it's the problem with the way I'm trying to use the reduction? I think each thread should count some part of array, and then merge it somehow. #pragma omp parallel for reduction (+: reasult[:i]) for (i = 0

Pause/resume a thread in C#

◇◆丶佛笑我妖孽 提交于 2021-02-05 08:40:34
问题 I try to pause all my threads when I reach a certain value but I can't do it. I would like that when I reach this value all threads are paused for 10 seconds and after these 10 seconds all threads start again. I tried that with : Threads.Sleep(); | Threads.Interrupt(); and Threads.Abort(); but nothing work. I tried what you can see in the code below. static void Main(string[] args) { for (int i = 0; i < 10; i++) { Threads.Add(new Thread(new ThreadStart(example))); Threads[i].Start(); } for

Forcing certain code to always run on the same thread

时间秒杀一切 提交于 2021-02-05 08:21:06
问题 We have an old 3rd party system (let's call it Junksoft® 95) that we interface with via PowerShell (it exposes a COM object) and I'm in the process of wrapping it in a REST API (ASP.NET Framework 4.8 and WebAPI 2). I use the System.Management.Automation nuget package to create a PowerShell in which I instantiate Junksoft's COM API as a dynamic object that I then use: //I'm omitting some exception handling and maintenance code for brevity powerShell = System.Management.Automation.PowerShell

Number of threads of Intel MKL functions inside OMP parallel regions

只愿长相守 提交于 2021-02-05 08:08:50
问题 I have a multithreaded code in C, using OpenMP and Intel MKL functions. I have the following code: omp_set_num_threads(nth); #pragma omp parallel for private(l,s) schedule(static) for(l=0;l<lines;l++) { for(s=0;s<samples;s++) { out[l*samples+s]=mkl_ddot(&bands, &hi[s*bands+l], &inc_one, &hi_[s*bands+l], &inc_one); } }//fin for l I want to use all the cores of the multicore processor (the value of nth) in this pramga. But I want that each core computes a single mkl_ddot function independently

Number of threads of Intel MKL functions inside OMP parallel regions

白昼怎懂夜的黑 提交于 2021-02-05 08:07:22
问题 I have a multithreaded code in C, using OpenMP and Intel MKL functions. I have the following code: omp_set_num_threads(nth); #pragma omp parallel for private(l,s) schedule(static) for(l=0;l<lines;l++) { for(s=0;s<samples;s++) { out[l*samples+s]=mkl_ddot(&bands, &hi[s*bands+l], &inc_one, &hi_[s*bands+l], &inc_one); } }//fin for l I want to use all the cores of the multicore processor (the value of nth) in this pramga. But I want that each core computes a single mkl_ddot function independently