multithreading

Cancel execution of command if it takes too long

帅比萌擦擦* 提交于 2021-02-08 19:56:09
问题 I am currently working on a piece of software that uses an assembly from a different department. I call a Method from this assembly like this: using (var connection = (IConnection) Factory.GetObject(typeof (IConnection))) The code used to work perfectly fine. But for the last few minutes it seemed like my program was doing nothing when I tried to launch it. Pressing pause while debugging showed me it got "stuck" at the line above. My guess is they're just doing some maintenance or something

Cancel execution of command if it takes too long

瘦欲@ 提交于 2021-02-08 19:56:03
问题 I am currently working on a piece of software that uses an assembly from a different department. I call a Method from this assembly like this: using (var connection = (IConnection) Factory.GetObject(typeof (IConnection))) The code used to work perfectly fine. But for the last few minutes it seemed like my program was doing nothing when I tried to launch it. Pressing pause while debugging showed me it got "stuck" at the line above. My guess is they're just doing some maintenance or something

C++ Multithread Java JNI method Call

筅森魡賤 提交于 2021-02-08 19:55:18
问题 I have a simple class in Java: public class MyClass { public static void dummyTest() { } } And in C++ I do the following JNI Call: void c_call_function() { JNIEnv *env ...// the JNIEnv initialization in JNI... jclass clazz ...// the class initialization in JNI... jmethodID mid_dummyTest = env->GetStaticMethodID(clazz, "dummyTest", "()V"); env->CallStaticIntMethod(clazz, mid_dummyTest); } If a single program calls the static method c_call_function() it is ok. But if a multithread program calls

BlockingCollection with Parallel.For hangs?

陌路散爱 提交于 2021-02-08 19:43:56
问题 I'm playing around with BlockingCollection to try to understand them better, but I'm struggling to understand why my code hangs when it finishes processing all my items when I use a Parallel.For I'm just adding a number to it (producer?): var blockingCollection = new BlockingCollection<long>(); Task.Factory.StartNew(() => { while (count <= 10000) { blockingCollection.Add(count); count++; } }); Then I'm trying to process (Consumer?): Parallel.For(0, 5, x => { foreach (long value in

BlockingCollection with Parallel.For hangs?

浪子不回头ぞ 提交于 2021-02-08 19:43:53
问题 I'm playing around with BlockingCollection to try to understand them better, but I'm struggling to understand why my code hangs when it finishes processing all my items when I use a Parallel.For I'm just adding a number to it (producer?): var blockingCollection = new BlockingCollection<long>(); Task.Factory.StartNew(() => { while (count <= 10000) { blockingCollection.Add(count); count++; } }); Then I'm trying to process (Consumer?): Parallel.For(0, 5, x => { foreach (long value in

BlockingCollection with Parallel.For hangs?

房东的猫 提交于 2021-02-08 19:43:20
问题 I'm playing around with BlockingCollection to try to understand them better, but I'm struggling to understand why my code hangs when it finishes processing all my items when I use a Parallel.For I'm just adding a number to it (producer?): var blockingCollection = new BlockingCollection<long>(); Task.Factory.StartNew(() => { while (count <= 10000) { blockingCollection.Add(count); count++; } }); Then I'm trying to process (Consumer?): Parallel.For(0, 5, x => { foreach (long value in

BlockingCollection with Parallel.For hangs?

拜拜、爱过 提交于 2021-02-08 19:42:39
问题 I'm playing around with BlockingCollection to try to understand them better, but I'm struggling to understand why my code hangs when it finishes processing all my items when I use a Parallel.For I'm just adding a number to it (producer?): var blockingCollection = new BlockingCollection<long>(); Task.Factory.StartNew(() => { while (count <= 10000) { blockingCollection.Add(count); count++; } }); Then I'm trying to process (Consumer?): Parallel.For(0, 5, x => { foreach (long value in

Volatile for structs and collections of structs

点点圈 提交于 2021-02-08 14:36:47
问题 I would like to use net wisdom to clarify some moments regarding multi-threading in .net. There are a lot of stuff in the internet about it however I was not able to find a good answer to my question. Let say we want to maintain a state of something in our class with safety for concurrent threads. Easy case is when state is int: class Class1 { volatile int state = 0; public int State { get { return state; } } public Action<int> StateUpdated; public void UpdateState(int newState) { state =

Volatile for structs and collections of structs

最后都变了- 提交于 2021-02-08 14:36:07
问题 I would like to use net wisdom to clarify some moments regarding multi-threading in .net. There are a lot of stuff in the internet about it however I was not able to find a good answer to my question. Let say we want to maintain a state of something in our class with safety for concurrent threads. Easy case is when state is int: class Class1 { volatile int state = 0; public int State { get { return state; } } public Action<int> StateUpdated; public void UpdateState(int newState) { state =

Minimal-locking thread-safe hashtable?

白昼怎懂夜的黑 提交于 2021-02-08 14:19:21
问题 Are there any available implementations of a Hashtable that provide thread safety with minimal locking in .NET? Or in another language that can be ported to .NET? We're looking for something in between using a BCL Dictionary<,> class with lock() and a distributed caching application like memcached or Velocity. The intended use is for a cache with thousands of readers reading out immutable values based on keys (either numbers or guids, we haven't decided which yet). There will be far less