thread-safety

Is it safe to call a synchronized method from another synchronized method?

巧了我就是萌 提交于 2019-12-18 10:21:10
问题 If a synchronized method calls another synchronized method, is it thread safe? void synchronized method1() { method2() } void synchronized method2() { } 回答1: Yes, when you mark methods as synchronized , then you are really doing this: void method1() { synchronized (this) { method2() } } void method2() { synchronized (this) { } } When the thread call gets into method2 from method1, then it will ensure that it holds the lock to this , which it will already, and then it can pass through. When

Achieving Thread-Safety

↘锁芯ラ 提交于 2019-12-18 10:15:09
问题 Question How can I make sure my application is thread-safe? Are their any common practices, testing methods, things to avoid, things to look for? Background I'm currently developing a server application that performs a number of background tasks in different threads and communicates with clients using Indy (using another bunch of automatically generated threads for the communication). Since the application should be highly availabe, a program crash is a very bad thing and I want to make sure

How to create a thread/Task with a continuous loop?

Deadly 提交于 2019-12-18 10:07:12
问题 I am looking for the correct way/structure to create a loop in a Thread/Task ... The reason for this is, i need to check the DB every 15sec for report requests. This is what i tried so far, but i get OutOfMemoryException : private void ViewBase_Loaded(object sender, RoutedEventArgs e) { //On my main view loaded start thread to check report requests. Task.Factory.StartNew(() => CreateAndStartReportRequestTask()); } private void CreateAndStartReportRequestTask() { bool noRequest = false; do { /

Find if the installed PHP is threadsafe or nonthreadsafe?

只谈情不闲聊 提交于 2019-12-18 10:06:49
问题 How do I find out whether the installed version of PHP is threadsafe or not thread safe? Please note that I'm not asking the difference between a threadsafe/non thread safe installation. I would like to find out what is installed currently. 回答1: Open a phpinfo() and search for the line Thread safety . For a thread-safe build you should find enable . As specified in the comments by Muhammad Gelbana you can also use: On Windows : php -i|findstr "Thread" On *nix: php -i|grep Thread 回答2: If you

Can an integer be shared between threads safely?

混江龙づ霸主 提交于 2019-12-18 07:50:33
问题 Is there a problem with multiple threads using the same integer memory location between pthreads in a C program without any synchronization utilities? To simplify the issue, Only one thread will write to the integer Multiple threads will read the integer This pseudo-C illustrates what I am thinking void thread_main(int *a) { //wait for something to finish //dereference 'a', make decision based on its value } int value = 0; for (int i=0; i<10; i++) pthread_create(NULL,NULL,thread_main,&value);

Concurrent add on non threadsafe HashSet - what is the worst that could happen?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 07:15:20
问题 Situation: Multiple Threads are only adding values to a non threadsafe java.util.HashSet and no other operation is done on the Set until these threads have been stopped. Question: What is the worst that could happen? 回答1: That depends on what you consider as being "worst". I'm not sure whether this question aimed at a detailed, technical analysis of the current implementation considering all possible race conditions and the nitty-gritty details of the Java memory model. So if the question is:

Reading values from a different thread

不问归期 提交于 2019-12-18 07:04:10
问题 I'm writing software in Go that does a lot of parallel computing. I want to collect data from worker threads and I'm not really sure how to do it in a safe way. I know that I could use channels but in my scenario they make it more complicated since I have to somehow synchronize messages (wait until every thread sent something) in the main thread. Scenario The main thread creates n Worker instances and launches their work() method in a goroutine so that the workers each run in their own thread

Thread safety with Dictionary<int,int> in .Net

你。 提交于 2019-12-18 05:47:19
问题 I have this function: static Dictionary<int, int> KeyValueDictionary = new Dictionary<int, int>(); static void IncreaseValue(int keyId, int adjustment) { if (!KeyValueDictionary.ContainsKey(keyId)) { KeyValueDictionary.Add(keyId, 0); } KeyValueDictionary[keyId] += adjustment; } Which I would have thought would not be thread safe. However, so far in testing it I have not seen any exceptions when calling it from multiple threads at the same time. My questions: Is it thread safe or have I just

C# and thread-safety of a bool

£可爱£侵袭症+ 提交于 2019-12-18 05:38:45
问题 I am very confused about this subject - whether reading/toggling a bool value is thread-safe. // case one, nothing private bool v1; public bool V1 { get { return v1; } set { v1 = value; } } // case two, with Interlocked on set private int v2; public int V2 { get { return v2; } set { Interlocked.Exchange(ref v2, value); } } // case three, with lock on set private object fieldLock = new object(); private bool v3; public bool V3 { get { return v3; } set { lock (fieldLock) v3 = value; } } Are all

Is std::ifstream thread-safe & lock-free?

独自空忆成欢 提交于 2019-12-18 05:11:55
问题 I intend to perform opening for reading a single file from many threads using std::ifstream. My concern is if std::ifstream is thread-safe & lock-free? More details: I use g++ 4.4 on Ubuntu & Windows XP, 4.0 on Leopard. Each thread creates its own instance of std::ifstream Thanks in advance! 回答1: That is implementation defined. Standard C++ says absolutely nothing about threading, and therefore any assumptions about threads inherently invoke unspecified or implementation defined behavior. We