thread-safety

What actual cause the StringBuilder fails in multi threading environment

流过昼夜 提交于 2019-12-24 05:13:08
问题 StringBuffer is synchronized but StringBuilder is not ! This has been discussed deeply at Difference between StringBuilder and StringBuffer. There is an example code there (Answered by @NicolasZozol), which address two issues: compares the performance of these StringBuffer and StringBuilder shows the StringBuilder could fail in a multithread environment. My question is about second part , exactly what makes it to go wrong?! When you run the code some times, the stack trace is displayed as

How do you choose gems for a high throughput multithreaded Rails app? [closed]

坚强是说给别人听的谎言 提交于 2019-12-24 05:05:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Basically, I got burnt by EventMachine which claimed JRuby compatibility but the java implementation failed on thread safety issues in standard patterns ( Thread.new{EM.run} doesn't work under JRuby for example) - we're talking pretty basic EM functions here. Unfortunately, most

How do you choose gems for a high throughput multithreaded Rails app? [closed]

时间秒杀一切 提交于 2019-12-24 05:05:18
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Basically, I got burnt by EventMachine which claimed JRuby compatibility but the java implementation failed on thread safety issues in standard patterns ( Thread.new{EM.run} doesn't work under JRuby for example) - we're talking pretty basic EM functions here. Unfortunately, most

Opinions, Suggestions on using a thread in IIS 7 hosted ASP.Net application to avoid a Stack Overflow Exception

一曲冷凌霜 提交于 2019-12-24 02:58:09
问题 In a ASP.Net web application, when you have a stack intensive operation to run, a stackoverflow exception is thrown on IIS when the stack size crosses the IIS set limit of 256K. A regular winform application however has a limit of 1MB. So the exception would not occur when running the same operation in a Winform application. There is no recursion or any other code specific issues here. There are ways to work around the problem like using EditBin on w3wp.exe, but it’s not supported. Other

Accidental Complexity in OpenSSL HMAC functions

空扰寡人 提交于 2019-12-24 02:49:09
问题 SSL Documentation Analaysis This question is pertaining the usage of the HMAC routines in OpenSSL. Since Openssl documentation is a tad on the weak side in certain areas, profiling has revealed that using the: unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, int n, unsigned char *md, unsigned int *md_len); From here, shows 40% of my library runtime is devoted to creating and taking down HMAC_CTX 's behind the scenes. There are also two additional

What are the dangers of using Session.SyncRoot for locking per session?

落爺英雄遲暮 提交于 2019-12-24 01:57:06
问题 I have a race condition with the following code if two requests come in really close together in an ASP.NET MVC app: var workload = org.Workloads.SingleOrDefault(p => ...conditions...); if (workload == null) { workload = org.CreateWorkload(id); } workload and org are EntityFramework objects. The call to CreateWorkload adds a row to a Workloads table in the database. ( We really should enforce this with a UNIQUE constraint on the table, but I can't now that the table has some dirty data in it.

Multithreading - In an array what should I protect?

眉间皱痕 提交于 2019-12-24 01:53:39
问题 I'm working on some code that has a global array that can be accessed by two threads for reading writing purposes. There will be no batch processing where a range of indexes are read or written, so I'm trying to figure out if I should lock the entire array or only the array index I am currently using. The easiest solution would be to consider the array a CS and put a big fat lock around it, but can I avoid this and just lock an index? Cheers. 回答1: Locking one index implies that you can keep

Can different threads insert into a map if they always use different keys?

空扰寡人 提交于 2019-12-24 01:29:06
问题 I'm trying to design a message queue for an object. There is a set of X threads that can all send message (to be processed later) to this object. If I have a std::map<thread_id_t, message> , is this thread safe, assuming thread one only adds messages with a key of 1, thread 2 to key 2, etc..? 回答1: std::map is not thread safe for multiple simultaneous writers. One of the many reasons why STL maps are not thread safe is that the underlying implementation of an STL map is an AVL tree that needs

Django and threading.local() quirks?

不羁的心 提交于 2019-12-24 00:48:31
问题 Recently I've started using threading.local() as way for some apis to store and access state for duration of request without having to access request object. So lets say I have certain code: _thread_local = threading.local() _thread_local.theme = 'darkblues' How long does that _thread_local.theme variable lasts? Do I have to manually unset it at the end of request in, say, custom middleware? Or it's deleted by Django automatically after it finishes processing request? 回答1: It will last as

Is it possible to group/isolate tasks in ThreadPool when using WaitHandle.WaitAll?

耗尽温柔 提交于 2019-12-24 00:35:32
问题 The scenario I am facing is as below. Because ThreadPool is 1 instance per process so my question is that would method 1 cancel tasks queued by method 2 after 3 seconds ? http request comes in *method 1 gets executed first*: ThreadPool.QueueUserWorkItem x 3 WaitHandle.WaitAll for 3 seconds *method 2 gets executed after method 1*: ThreadPool.QueueUserWorkItem x 10 WaitHandle.WaitAll for 10 seconds Sorry I think I totally misunderstood the use of WaitHandle. It seems that if I do below