Fixed Thomas's Bug.

In short:
- When a large amount of input was recieved, the server would hang.
- The server would hang on queue->lock for the input queue, in pushQueue().
- Upon debugging, it was revealed that queue->lock was actually false at this time.
- GCC had optimized out the actual loop, leaving it to get stuck even though the variable had changed.
- Adding the volatile keyword to the lock fixed this issue.
This commit is contained in:
Barry Kane 2023-02-08 17:15:23 +00:00
parent c2c77d6343
commit a38cbb70a8
3 changed files with 5 additions and 2 deletions

View File

@ -24,6 +24,6 @@ clean:
rm -f $(clientobj) $(serverobj) SilverMUDClient SilverMUDServer SilverMUDClientDebug SilverMUDServerDebug
all: clean SilverMUDClient SilverMUDServer
all: CFLAGS += -Wall -Wextra -Ofast
all: CFLAGS += -Wall -Wextra -Ofast
debug: CFLAGS += -Wall -Wextra -pg -ggdb -Og -D debug
debug: clean SilverMUDClientDebug SilverMUDServerDebug

View File

@ -157,6 +157,9 @@ void popQueue(queue * queue)
// Adds data to the back of a queue:
void pushQueue(queue * queue, void * data, queueDataType type)
{
// Check if the queue is locked:
while (queue->lock);
// Create a new node:
queueNode * newNode = malloc(sizeof(queueNode));
newNode->type = type;

View File

@ -37,7 +37,7 @@ typedef struct queueNode
typedef struct queue
{
bool lock;
volatile bool lock;
size_t itemCount;
queueNode * front;
queueNode * back;