thread-safety

Is CreateDirectory() in C# thread-safe?

六眼飞鱼酱① 提交于 2020-01-22 11:17:30
问题 Can I safely attempt to create the same directory from two different threads, without having one of them throw an exception, or run into other issues? Note that according to MSDN, it is OK to call CreateDirectory() on a directory which already exists, in which case the method is expected to do nothing. 回答1: The Directory.CreateDirectory call itself is safe to make from multiple threads. It will not corrupt program or file system state if you do so. However it's not possible to call Directory

Is CreateDirectory() in C# thread-safe?

徘徊边缘 提交于 2020-01-22 11:17:16
问题 Can I safely attempt to create the same directory from two different threads, without having one of them throw an exception, or run into other issues? Note that according to MSDN, it is OK to call CreateDirectory() on a directory which already exists, in which case the method is expected to do nothing. 回答1: The Directory.CreateDirectory call itself is safe to make from multiple threads. It will not corrupt program or file system state if you do so. However it's not possible to call Directory

Is CreateDirectory() in C# thread-safe?

老子叫甜甜 提交于 2020-01-22 11:17:12
问题 Can I safely attempt to create the same directory from two different threads, without having one of them throw an exception, or run into other issues? Note that according to MSDN, it is OK to call CreateDirectory() on a directory which already exists, in which case the method is expected to do nothing. 回答1: The Directory.CreateDirectory call itself is safe to make from multiple threads. It will not corrupt program or file system state if you do so. However it's not possible to call Directory

Seeding Multiple Random Number Generators

▼魔方 西西 提交于 2020-01-20 05:04:41
问题 I have recently been discussing the initialisation of multiple random number generators of the same type in the comments of another post and in that discussion we asked the following questions: 1) Is it a good idea to create multiple instances of the same random number generator with different seeds and use these random number generators in different parts of the program? 2) In particular, can the technique of creating random number generators using the .Net Random class, seeded as below, and

Seeding Multiple Random Number Generators

大城市里の小女人 提交于 2020-01-20 05:03:16
问题 I have recently been discussing the initialisation of multiple random number generators of the same type in the comments of another post and in that discussion we asked the following questions: 1) Is it a good idea to create multiple instances of the same random number generator with different seeds and use these random number generators in different parts of the program? 2) In particular, can the technique of creating random number generators using the .Net Random class, seeded as below, and

What is the preferred way to modify a value in ConcurrentHashMap?

六月ゝ 毕业季﹏ 提交于 2020-01-20 04:14:48
问题 Let's say I have a Concurrent Map that is high-read, low-write, and needs to store application data: ConcurrentMap<UUID, Data> map = new ConcurrentHashMap<UUID, Data>(); Then, during startup and through user input, data is added to the map: public void createData(Data newData) { map.put(newId, newData); // etc... } If I then need to change the data, should I: A) Make the Data class objects immutable, and then conduct a put operation every time a change is needed for a Data object: public void

how to make an application thread safe?

烂漫一生 提交于 2020-01-19 18:20:54
问题 I thought thread safe, in particular, means it must satisfy the need for multiple threads to access the same shared data. But, it seems this definition is not enough. Can anyone please list out the things to be done or taken care of to make an application thread safe . If possible, give an answer with respect to C/C++ language. 回答1: There are several ways in which a function can be thread safe. It can be reentrant . This means that a function has no state, and does not touch any global or

Are C# auto-implemented static properties thread-safe?

旧城冷巷雨未停 提交于 2020-01-19 05:37:09
问题 I would like to know if C# automatically implemented properties, like public static T Prop { get; set; } , are thread-safe or not. Thanks! 回答1: It appears not. This is the decompilation with Reflector: private static string Test { [CompilerGenerated] get { return <Test>k__BackingField; } [CompilerGenerated] set { <Test>k__BackingField = value; } } 回答2: Section 10.7.4 of the C# specification states: When a property is specified as an automatically implemented property, a hidden backing field

C# SerialPort: ReadLine not working

无人久伴 提交于 2020-01-17 05:40:08
问题 i'm having issues reading input from a serial port in C#. The device, that is connected via usb, is a ELM327-Chip for reading the OBD-port of the car. My Code consist of two threads: A Write- and a Read-Thread. It looks like the following: static volatile SerialPort moPort; ... moPort = new SerialPort("COM3"); moPort.BaudRate = 38400; moPort.Parity = Parity.None; moPort.DataBits = 8; moPort.StopBits = StopBits.One; moPort.NewLine = "\r"; moPort.ReadTimeout = 5000; moPort.Open(); Write-Thread:

C++ Meyers Singleton - thread safe (code equivalent for mutex?)

邮差的信 提交于 2020-01-17 05:08:09
问题 I was pointed last week about a piece of code like this: #include <pthread.h> namespace NSTest { class SingletonClass { public: static SingletonClass & getInstance() { static pthread_mutex_t mutex; pthread_mutex_lock(&mutex); if(singletonPtr==nullptr) { createInstence(); } return (*singletonPtr); pthread_mutex_unlock(&mutex); } private: static void createInstence() { static SingletonClass static_SingletonClass; singletonPtr=&static_SingletonClass; } static SingletonClass * singletonPtr; };