Concurrent HashSet in .NET Framework?

I have the following class. class Test{ public HashSet<string> Data = new HashSet<string>(); } I need to change the field “Data” from different threads, so I would like some opinions on my current thread-safe implementation. class Test{ public HashSet<string> Data = new HashSet<string>(); public void Add(string Val){ lock(Data) Data.Add(Val); } public void Remove(string Val){ lock(Data) … Read more

Java synchronized method lock on object, or method?

If I have 2 synchronized methods in the same class, but each accessing different variables, can 2 threads access those 2 methods at the same time? Does the lock occur on the object, or does it get as specific as the variables inside the synchronized method? Example: class X { private int a; private int … Read more

Is local static variable initialization thread-safe in C++11? [duplicate]

This question already has answers here: Is Meyers’ implementation of the Singleton pattern thread safe? (6 answers) Closed 4 years ago. I know this is an often asked question, but as there are so many variants, I’d like to re-state it, and hopefully have an answer reflecting the current state. Something like Logger& g_logger() { … Read more

Queue.Queue vs. collections.deque

I need a queue which multiple threads can put stuff into, and multiple threads may read from. Python has at least two queue classes, Queue.Queue and collections.deque, with the former seemingly using the latter internally. Both claim to be thread-safe in the documentation. However, the Queue docs also state: collections.deque is an alternative implementation of … Read more

Use cases for RxJava schedulers

In RxJava there are 5 different schedulers to choose from: immediate(): Creates and returns a Scheduler that executes work immediately on the current thread. trampoline(): Creates and returns a Scheduler that queues work on the current thread to be executed after the current work completes. newThread(): Creates and returns a Scheduler that creates a new … Read more

Why is Java’s SimpleDateFormat not thread-safe? [duplicate]

This question already has answers here: “Java DateFormat is not threadsafe” what does this leads to? (11 answers) Closed 5 years ago. Please tell with a code example why is SimpleDateFormat not threadsafe. What is the problem in this class? Is The problem with format function of SimpleDateFormat? Please give a code which demonstrates this … Read more