thread-safety

Ways to detect deadlock in a live application

懵懂的女人 提交于 2020-04-15 03:12:49
问题 What are the ways to detect deadlocks in a live multi-threaded application? If we found there is a deadlock, are there any ways to resolve it, without taking down/restarting the application? 回答1: There are two popular ways to detect deadlocks. One is to have threads set checkpoints. For example, if you have a thread that has a work loop, you set a timer at the beginning of doing work that's set for longer than you think the work could possibly take. If the timer fires, you assume the thread

Ways to detect deadlock in a live application

喜你入骨 提交于 2020-04-15 03:12:43
问题 What are the ways to detect deadlocks in a live multi-threaded application? If we found there is a deadlock, are there any ways to resolve it, without taking down/restarting the application? 回答1: There are two popular ways to detect deadlocks. One is to have threads set checkpoints. For example, if you have a thread that has a work loop, you set a timer at the beginning of doing work that's set for longer than you think the work could possibly take. If the timer fires, you assume the thread

Memory lock to ensure shared data can be read from by many threads, but only written to by one?

烂漫一生 提交于 2020-04-07 05:38:18
问题 I am trying to write a C# program where values in a list A are checked against a particular value x in a thread. I would like the threads to compare their x values to each of the ones in the list, and if it is not found, I would like them to add their value x to A . The thread will then get a new x from a list in it's private memory, and begin comparing it to the values in A again. The objective of this program is to make A a list of unique values, and contain all of the values of the lists

C#, is there such a thing as a “thread-safe” stream?

半城伤御伤魂 提交于 2020-03-11 20:09:51
问题 I am redirecting the output of a process into a streamreader which I read later. My problem is I am using multiple threads which SHOULD have separate instances of this stream. When I go to read this stream in, the threading fudges and starts executing oddly. Is there such a thing as making a thread-safe stream? EDIT: I put locks on the ReadToEnd on the streamreader, and the line where I did: reader = proc.StandardOutput; 回答1: There's a SyncrhonizedStream built into the framework, they just

Is a comparison on monotonic count integer safe?

巧了我就是萌 提交于 2020-03-03 12:07:53
问题 I know in a multithread environment doing this is not safe: if (some_var > 0) { // Do something. } Because when comparing, there might be another thread changing the value. What if some_var is a counter. That is, it can only increment, never decreases. Then is following operation thread safe? if(some_counter >0) { // Do something. } Also does it make difference if some_counter is either byte, or int32, int64? 回答1: What if some_var is a counter. That is, it can only increment, never decreases.

Is a comparison on monotonic count integer safe?

孤街醉人 提交于 2020-03-03 12:06:36
问题 I know in a multithread environment doing this is not safe: if (some_var > 0) { // Do something. } Because when comparing, there might be another thread changing the value. What if some_var is a counter. That is, it can only increment, never decreases. Then is following operation thread safe? if(some_counter >0) { // Do something. } Also does it make difference if some_counter is either byte, or int32, int64? 回答1: What if some_var is a counter. That is, it can only increment, never decreases.

Threading in a Windows Service

别说谁变了你拦得住时间么 提交于 2020-02-23 08:28:11
问题 I've created an app which uses Observable Lists. I've made the ObservableList class threadsafe (I think) and it's working fine now in my application. Now I'm trying to install my application as a service. This works fine as well, up untill the point something gets added to the list. I think the thread there just dies. I've got the following code: /// <summary> /// Creates a new empty ObservableList of the provided type. /// </summary> public ObservableList() { //Assign the current Dispatcher

Copy constructor from non-const argument suggested by thread-safety rules?

淺唱寂寞╮ 提交于 2020-02-21 10:29:14
问题 This bounty has ended . Answers to this question are eligible for a +400 reputation bounty. Bounty grace period ends in 23 hours . alfC is looking for an answer from a reputable source : “A well argumented answer or a reference to an existing good practice will be awarded.” I have a wrapper to some piece of legacy code. class A{ L* impl_; // the legacy object has to be in the heap, could be also unique_ptr A(A const&) = delete; L* duplicate(){L* ret; legacy_duplicate(impl_, &L); return ret;}

Copy constructor from non-const argument suggested by thread-safety rules?

做~自己de王妃 提交于 2020-02-21 10:25:32
问题 This bounty has ended . Answers to this question are eligible for a +400 reputation bounty. Bounty grace period ends in 23 hours . alfC is looking for an answer from a reputable source : “A well argumented answer or a reference to an existing good practice will be awarded.” I have a wrapper to some piece of legacy code. class A{ L* impl_; // the legacy object has to be in the heap, could be also unique_ptr A(A const&) = delete; L* duplicate(){L* ret; legacy_duplicate(impl_, &L); return ret;}

Threadsafe vs Synchronized

余生颓废 提交于 2020-02-17 09:11:08
问题 I'm new to java. I'm little bit confused between Threadsafe and synchronized. Thread safe means that a method or class instance can be used by multiple threads at the same time without any problems occurring. Where as Synchronized means only one thread can operate at single time. So how they are related to each other? 回答1: The definition of thread safety given in Java Concurrency in Practice is: A class is thread-safe if it behaves correctly when accessed from multiple threads, regardless of