Is console.writeline thread safe? [duplicate]
It’s safe! From the .NET API browser: Console I/O Streams […] I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams.
It’s safe! From the .NET API browser: Console I/O Streams […] I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams.
Please see my updates at the end of the answer, the situation has dramatically changed since Visual Studio 2015. The original answer is below. I made a very simple test and according to my measurements the std::mutex is around 50-70x slower than CRITICAL_SECTION. std::mutex: 18140574us CRITICAL_SECTION: 296874us Edit: After some more tests it turned out … Read more
A precise technical definition that everyone agrees on is difficult to come up with. Informally, “thread safe” simply means “is reasonably well-behaved when called from multiple threads”. The object will not crash or produce crazy results when called from multiple threads. The question you actually need to get answered if you intend to do multi-threaded … Read more
Examples 2 and 3 are exactly the same. Modules and classes are also objects, and defining a singleton method on a object actually defines it on its singleton class. With that said, and since you have already established instance variable access is thread safe, examples 2 and 3 are thread safe. Example 1 should also … Read more
It’s not thread-safe; simultaneous calls may interleave, and mess with the local variables. The common approach is to use the master-slave pattern (now called farmer-worker pattern in PC). Make a third thread which generates data, and add a Queue between the master and the slaves, where slaves will read from the queue, and the master … Read more
The operations std::atomic makes available on any trivially copyable type are pretty basic. You can construct and destroy atomic<T>, you can ask if the type is_lock_free(), you can load and store copies of T, and you can exchange values of T in various ways. If that’s sufficient for your purpose then you might be better … Read more
The C++ standard makes certain threading guarantees for all the classes in the standard C++ library. These guarantees may not be what you’d expect them to be but for all standard C++ library classes certain thread safety guarantees are made. Make sure you read the guarantees made, though, as the threading guarantees of standard C++ … Read more
Ignoring a checked exception is never considered to be safe. It may seem okay for you at the moment, but if any other programmer uses your code/API, they should expect the standard behaviour: Which is, the thread “reacting” to an interrupt call, but with whatever “reaction” the thread’s documentation describes. I mean it’s up to … Read more
Initializing ThreadStatic fields is a little tricky. In particular there is this caveat: Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. in the MSDN Docs. What this means is that the thread running when the class … Read more
if you read the Little redis book at some point this sentence comes. “You might not know it, but Redis is actually single-threaded, which is how every command is guaranteed to be atomic. While one command is executing, no other command will run.” Have a look in http://openmymind.net/2012/1/23/The-Little-Redis-Book/ for more information Regards