New answers tagged

5

The Purse class could be rewritten in the following way: public class Purse { private ArrayList coins = new ArrayList(); private readonly object lockObject = new object(); public void Add(Coin aCoin) { lock (lockObject) { coins.Add(aCoin); } } public void RemoveCoin(Coin aCoin) { lock (...


8

Taking a look at your Coin class, there are a few things that aren't quite idiomatic C#. The most obvious thing is that you're using what looks nearly like Java Doc comments. C# uses XML doc comments so this: /// Constructs a coin. /// @param aValue the monetary value of the coin /// @param aName the name of the coin Should be: /// <summary>Constructs ...


2

Do I need atomic? I have only one thread, can I use just thread::joinable() instead? If you only use an instance of struct X from one thread, then you could indeed use thread::joinable() to check whether the save thread is running. However, as soon as you have multiple threads accessing an X, then you need atomics, otherwise two threads can simultaneously ...


Top 50 recent answers are included