New answers tagged

3

Please take a look at this library for inspiration on how to state machine could be defined: https://projects.spring.io/spring-statemachine/ Should I change locking system to "fair"? => Could you please clarify what you are trying to achieve Will it work smoothly with 2 threads? (There's no possibility that the start()/stop() can be accessed at ...


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 ...


1

for(n = 0; cumsum <= u_rand; n++) cumsum += (double) distribution[n]/(double) norm; is not clear to me that distribution[n] will always use a n in the [0... LATTICE_SIZE-1] range. I suspect, depending on the roundings and sequencing of adding floating point numbers, code may iterate too far and attempt distribution[LATTICE_SIZE] which is bad. Best not ...


2

When compiling, always enable the warnings, then fix those warnings. A run of the code through the gcc compiler results in: gcc -ggdb3 -Wall -Wextra -Wconversion -pedantic -std=gnu11 -c "untitled2.c" -o "untitled2.o" untitled2.c: In function ‘calculate_avg_density’: untitled2.c:56:31: warning: conversion to ‘double’ from ‘long long ...


1

I'm not that great with threads, parallel programming so I won't comment about them... However, as for design decisions; I've taken your code and wrote my own version. I wouldn't say that the code that I'm about to present to you as an example is 100% bug proof. It does currently run and compile producing some interesting results! This has more to do with ...


2

Answers to your questions Is the Game object design easy to understand? It's not too hard. But I would have expected a struct Player (even if there is only one instance of it, so no need to put it in a container), and I also expected class Game to manage the monster thread. Does the scheduling mechanism make sense? Yes, but it is a bit too complicated. ...


Top 50 recent answers are included