multithreading

Is mersenne twister thread safe for cpp

我是研究僧i 提交于 2020-03-01 04:22:10
问题 #include <random> int f() { std::random_device seeder; std::mt19937 engine(seeder()); std::uniform_int_distribution<int> dist(1, 6); return dist(engine); } Can multiple threads call this function safely? Is the function thread safe? It is reduntant to call std::random_device seeder; and std::mt19937 engine(seeder()); every time? 回答1: No C++ std type uses global data in a non-thread-safe way. Two unrelated instances of such a type can be accessed in different threads. By default, one instance

Android: Best way of handling continuous pulling from server?

穿精又带淫゛_ 提交于 2020-02-29 05:15:08
问题 To start of, i should mention that i'm a newbie in Android (Not that much experience in Java at all tbh), so be easy on me. I am making an app that continuously pulls data from a server, and then returns data through a http post request. The question is, what is the best way to handle the actual pulling from the server? Should i be using AsyncTask or create another thread and let it run on that? Are there better methods for this purpose? I will be pulling data every 5 minutes. (I am aware

How to call same method of a different class in multithreaded way

怎甘沉沦 提交于 2020-02-28 19:38:09
问题 I have a method named process in two of my Classes, lets say CLASS-A and CLASS-B . Now in the below loop, I am calling process method of both of my classes sequentially meaning one by one and it works fine but that is the not the way I am looking for. for (ModuleRegistration.ModulesHolderEntry entry : ModuleRegistration.getInstance()) { final Map<String, String> response = entry.getPlugin().process(outputs); // write to database System.out.println(response); } Is there any way, I can call the

How to call same method of a different class in multithreaded way

喜你入骨 提交于 2020-02-28 19:34:06
问题 I have a method named process in two of my Classes, lets say CLASS-A and CLASS-B . Now in the below loop, I am calling process method of both of my classes sequentially meaning one by one and it works fine but that is the not the way I am looking for. for (ModuleRegistration.ModulesHolderEntry entry : ModuleRegistration.getInstance()) { final Map<String, String> response = entry.getPlugin().process(outputs); // write to database System.out.println(response); } Is there any way, I can call the

Java: BufferedReader hangs forever on close() and StreamDecoder doesn't respect thread interrupt

五迷三道 提交于 2020-02-28 15:22:31
问题 I have a Java program which launches a separate subprocess represented by the Process class, and then attaches listeners which look at the stdout/stderr of the Process. In some cases, the Process will hang and stop being able to make progress, at which time the TimeLimiter will throw a TimeoutException, attempt to interrupt the underlying thread which is actually doing the readLine() call, and then kill the Process using kill -9 and close the stdout and stderr streams from the Process object.

Futex throughput on Linux

♀尐吖头ヾ 提交于 2020-02-28 07:03:41
问题 I have an async API which wraps some IO library. The library uses C style callbacks, the API is C++, so natural choice (IMHO) was to use std::future/std::promise to build this API. Something like std::future<void> Read(uint64_t addr, byte* buff, uint64_t buffSize) . However, when I was testing the implementation I saw that the bottleneck is the future/promise , more precisely, the futex used to implement promise/future . Since the futex, AFAIK, is user space and the fastest mechanism I know

Futex throughput on Linux

…衆ロ難τιáo~ 提交于 2020-02-28 07:03:38
问题 I have an async API which wraps some IO library. The library uses C style callbacks, the API is C++, so natural choice (IMHO) was to use std::future/std::promise to build this API. Something like std::future<void> Read(uint64_t addr, byte* buff, uint64_t buffSize) . However, when I was testing the implementation I saw that the bottleneck is the future/promise , more precisely, the futex used to implement promise/future . Since the futex, AFAIK, is user space and the fastest mechanism I know

What does 'intrinsify' mean in the JVM source code?

霸气de小男生 提交于 2020-02-27 22:38:58
问题 Does 'intrinsify' means that source code of JVM is somewhat 'conservative', but the JIT compiler can do some optimization when the JVM warms up? For example, UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetOrderedObject"); oop x = JNIHandles::resolve(x_h); oop p = JNIHandles::resolve(obj); void* addr = index_oop_from_field_offset_long(p, offset); OrderAccess::release(); if (UseCompressedOops) { oop_store

What does 'intrinsify' mean in the JVM source code?

佐手、 提交于 2020-02-27 22:38:18
问题 Does 'intrinsify' means that source code of JVM is somewhat 'conservative', but the JIT compiler can do some optimization when the JVM warms up? For example, UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) UnsafeWrapper("Unsafe_SetOrderedObject"); oop x = JNIHandles::resolve(x_h); oop p = JNIHandles::resolve(obj); void* addr = index_oop_from_field_offset_long(p, offset); OrderAccess::release(); if (UseCompressedOops) { oop_store

parallel excution and file writing on python

五迷三道 提交于 2020-02-27 09:10:22
问题 I have a very large datasets distributed in 10 big clusters and the task is to do some computations for each cluster and write (append) the results line by line into 10 files where each file contains the results obtained corresponding to each one of the 10 clusters, each cluster can be computed independently, and I want to parallelize the code into ten CPUs (or threads) such that I can do the computations on all the clusters at once, a simplified pseudo code for my task is the following: for