concurrency

Synchronization in java ForkJoinPool compute() method

南笙酒味 提交于 2020-06-01 05:07:07
问题 in Java: The Complete Reference we read: In general, a ForkJoinTask should not use synchronized methods or synchronized blocks of code. Also, you will not normally want to have the compute( ) method use other types of synchronization, such as a semaphore Why should I avoid synchronizing in compute()? Is it still possible in some situation to use synchronization such as semaphore or synchronized? What other method should I use from java.util.concurrent to have scallable number of threads as in

c# TaskFactory ContinueWhenAll unexpectedly running before all tasks complete

妖精的绣舞 提交于 2020-05-31 04:54:05
问题 I have a data processing program in C# (.NET 4.6.2; WinForms for the UI). I'm experiencing a strange situation where computer speed seems to be causing Task.Factory.ContinueWhenAll to run earlier than expected or some Tasks are reporting complete before actually running. As you can see below, I have a queue of up to 390 tasks, with no more than 4 in queue at once. When all tasks are complete, the status label is updated to say complete. The ScoreManager involves retrieving information from a

AsyncIO run in executor using ProcessPoolExecutor

半城伤御伤魂 提交于 2020-05-31 02:51:53
问题 I tried to combine blocking tasks and non-blocking (I/O bound) tasks using ProcessPoolExecutor and found it's behavior pretty unexpected. class BlockingQueueListener(BaseBlockingListener): def run(self): # Continioulsy listening a queue blocking_listen() class NonBlockingListener(BaseNonBlocking): def non_blocking_listen(self): while True: await self.get_message() def run(blocking): blocking.run() if __name__ == "__main__": loop = asyncio.get_event_loop() executor = ProcessPoolExecutor()

Java - exact meaning http.maxConnections

时光总嘲笑我的痴心妄想 提交于 2020-05-30 19:28:14
问题 Recently I came across 2 slightly different definitions of the java property http.maxConnections provided by Oracle. here it's defined as If HTTP keepalive is enabled this value determines the maximum number of idle connections that will be simultaneously kept alive, per destination. whereas here it's defined as Indicates the maximum number of connections per destination to be kept alive at any given time What confuses me is the word idle mentioned in the first definition above. Considering

Java - exact meaning http.maxConnections

a 夏天 提交于 2020-05-30 19:27:12
问题 Recently I came across 2 slightly different definitions of the java property http.maxConnections provided by Oracle. here it's defined as If HTTP keepalive is enabled this value determines the maximum number of idle connections that will be simultaneously kept alive, per destination. whereas here it's defined as Indicates the maximum number of connections per destination to be kept alive at any given time What confuses me is the word idle mentioned in the first definition above. Considering

How can I measure how many threads are executing a piece of code?

余生颓废 提交于 2020-05-28 18:04:09
问题 I am trying to measure how many threads are executing a section of code at the same time. Currently i am (ab)using Semaphores for this, is there a better way? final int MAX_THREADS = Integer.MAX_VALUE; Semaphore s = new Semaphore(MAX_THREADS); s.acquire(); // start of section // do some computations // track how many threads are running the section trackThreads( (MAX_THREADS - s.availablePermits()) ); s.release(); // end of section 回答1: Use an AtomicInteger instead of a Semaphore . Something

Mediator deadlock on async await within background worker - how to detect thread calling itself

大兔子大兔子 提交于 2020-05-28 06:50:13
问题 I have a mediator which I have recently needed to synchronize one at a time message dispatch on a background thread but it is locking, demonstrated below. I post a command to a queue and return a task from a TaskCompletionSource: public Task<object> Send(object command, CancellationToken cancellationToken) { var item = new CommandItem() { Command = request, Tcs = new TaskCompletionSource<object>(), Ct = cancellationToken }; this.queue.Writer.WriteAsync(item); // just write and immediatly

question about modifing flag array in cuda

こ雲淡風輕ζ 提交于 2020-05-27 06:06:31
问题 i am doing a research about GPU programming and have a question about modifying global array in thread. __device__ float data[10] = {0,0,0,0,0,0,0,0,0,1}; __global__ void gradually_set_global_data() { while (1) { if (data[threadIdx.x + 1]) { atomicAdd(&data[threadIdx.x], data[threadIdx.x + 1]); break; } } } int main() { gradually_set_global_data<<<1, 9>>>(); cudaDeviceReset(); return 0; } The kernel should complete execution with data expected to hold [1,1,1,1,1,1,1,1,1,1], but it gets stuck

question about modifing flag array in cuda

空扰寡人 提交于 2020-05-27 06:05:28
问题 i am doing a research about GPU programming and have a question about modifying global array in thread. __device__ float data[10] = {0,0,0,0,0,0,0,0,0,1}; __global__ void gradually_set_global_data() { while (1) { if (data[threadIdx.x + 1]) { atomicAdd(&data[threadIdx.x], data[threadIdx.x + 1]); break; } } } int main() { gradually_set_global_data<<<1, 9>>>(); cudaDeviceReset(); return 0; } The kernel should complete execution with data expected to hold [1,1,1,1,1,1,1,1,1,1], but it gets stuck

question about modifing flag array in cuda

隐身守侯 提交于 2020-05-27 06:05:15
问题 i am doing a research about GPU programming and have a question about modifying global array in thread. __device__ float data[10] = {0,0,0,0,0,0,0,0,0,1}; __global__ void gradually_set_global_data() { while (1) { if (data[threadIdx.x + 1]) { atomicAdd(&data[threadIdx.x], data[threadIdx.x + 1]); break; } } } int main() { gradually_set_global_data<<<1, 9>>>(); cudaDeviceReset(); return 0; } The kernel should complete execution with data expected to hold [1,1,1,1,1,1,1,1,1,1], but it gets stuck