multithreading

Reading millions of small files with C#

半世苍凉 提交于 2020-07-09 08:54:56
问题 I have millions of log files which generating every day and I need to read all of them and put together as a single file to do some process on it in other app. I'm looking for the fastest way to do this. Currently I'm using Threads, Tasks and parallel like this: Parallel.For(0, files.Length, new ParallelOptions { MaxDegreeOfParallelism = 100 }, i => { ReadFiles(files[i]); }); void ReadFiles(string file) { try { var txt = File.ReadAllText(file); filesTxt.Add(tmp); } catch { } GlobalCls

std::async won't spawn a new thread when return value is not stored

房东的猫 提交于 2020-07-09 06:45:12
问题 Consider I have lamba foo which just does some stuff and doesn't need to return anything. When I do this: std::future<T> handle = std::async(std::launch::async, foo, arg1, arg2); Everything runs fine and the lamba will be spawned in a new thread. However, when I don't store the std::future which the std::async returns, the foo will be run in the main thread and block it. std::async(std::launch::async, foo, arg1, arg2); What am I missing here? 回答1: From just::thread documentation: If policy is

std::async won't spawn a new thread when return value is not stored

雨燕双飞 提交于 2020-07-09 06:42:59
问题 Consider I have lamba foo which just does some stuff and doesn't need to return anything. When I do this: std::future<T> handle = std::async(std::launch::async, foo, arg1, arg2); Everything runs fine and the lamba will be spawned in a new thread. However, when I don't store the std::future which the std::async returns, the foo will be run in the main thread and block it. std::async(std::launch::async, foo, arg1, arg2); What am I missing here? 回答1: From just::thread documentation: If policy is

How to mix atomic and non-atomic operations in C++?

故事扮演 提交于 2020-07-08 05:25:09
问题 The std::atomic types allow atomic access to variables, but I would sometimes like non-atomic access, for example when the access is protected by a mutex. Consider a bitfield class that allows both multi-threaded access (via insert) and single-threaded vectorized access (via operator|=): class Bitfield { const size_t size_, word_count_; std::atomic<size_t> * words_; std::mutex mutex_; public: Bitfield (size_t size) : size_(size), word_count_((size + 8 * sizeof(size_t) - 1) / (8 * sizeof(size

Background validation of state, reset on user action

无人久伴 提交于 2020-07-07 10:28:36
问题 I'm really new to threading multitasking/multithreading, but I'm working on a project where I think I need it. The user will be editing a fairly complex diagram, and I want the program to check for validity of the diagram. The validity check is non-trivial (polynomial time, though, not NP - seconds, not minutes or years, but I don't want to hold the user up for a few seconds after every change) so I would like the program to check for validity in the background and highlight inconsistencies

Java8 hangs up if getStackTrace() is called by one thread and lambda definition (via Unsafe.defineAnonymousClass) occurs in another thread

江枫思渺然 提交于 2020-07-07 09:27:02
问题 My Web application, which runs in Apache Tomcat/8.0.21, with JVM 1.8.0_45-b15 and Windows Server 2012 on a 16-core (32- with HT) Dual-Xeon NUMA machine, can get stuck, in some very unfortunate circumstances, when the actions described in the title occur at the same time in two different threads. The thread doing the first action ( getStackTrace() ) is trying to perform some diagnostic to detect which part of the system is slowing things down and gets stuck while calling Thread.dumpThreads .

Java8 hangs up if getStackTrace() is called by one thread and lambda definition (via Unsafe.defineAnonymousClass) occurs in another thread

会有一股神秘感。 提交于 2020-07-07 09:25:47
问题 My Web application, which runs in Apache Tomcat/8.0.21, with JVM 1.8.0_45-b15 and Windows Server 2012 on a 16-core (32- with HT) Dual-Xeon NUMA machine, can get stuck, in some very unfortunate circumstances, when the actions described in the title occur at the same time in two different threads. The thread doing the first action ( getStackTrace() ) is trying to perform some diagnostic to detect which part of the system is slowing things down and gets stuck while calling Thread.dumpThreads .

Java8 hangs up if getStackTrace() is called by one thread and lambda definition (via Unsafe.defineAnonymousClass) occurs in another thread

只愿长相守 提交于 2020-07-07 09:25:46
问题 My Web application, which runs in Apache Tomcat/8.0.21, with JVM 1.8.0_45-b15 and Windows Server 2012 on a 16-core (32- with HT) Dual-Xeon NUMA machine, can get stuck, in some very unfortunate circumstances, when the actions described in the title occur at the same time in two different threads. The thread doing the first action ( getStackTrace() ) is trying to perform some diagnostic to detect which part of the system is slowing things down and gets stuck while calling Thread.dumpThreads .

Clarification about keras.utils.Sequence

一笑奈何 提交于 2020-07-06 11:26:49
问题 Keras have very little info about keras.utils.Sequence, actually the only reason I want to derive my batch generator from keras.utils.Sequence is that I want to not to write thread pool with queue by myself, but I'm not sure if it's best choice for my task, here is my questions: What should __len__ return if I have random generator and I don't have any predefined 'list' with samples. How keras.utils.Sequence should be used with fit_generator , I'm interested in max_queue_size , workers , use

Clarification about keras.utils.Sequence

感情迁移 提交于 2020-07-06 11:26:12
问题 Keras have very little info about keras.utils.Sequence, actually the only reason I want to derive my batch generator from keras.utils.Sequence is that I want to not to write thread pool with queue by myself, but I'm not sure if it's best choice for my task, here is my questions: What should __len__ return if I have random generator and I don't have any predefined 'list' with samples. How keras.utils.Sequence should be used with fit_generator , I'm interested in max_queue_size , workers , use