Unsafe mutex implementation? No real multithreading?

SerraAvenger

Cuz I can
Reaction score
234
Code:
while (#PARAM(lock)) {
    Wait(1.0, c_timeGame);
}
#PARAM(lock) = true;
#SUBFUNCS(actions)
#PARAM(lock) = false;

wth?
 
Reaction score
54
Seems to do what it's supposed to do.
Prevents threads from running a critical section more than one at a time.

Were you expecting a queue behaviour for the next thread to go in? It shouldn't be hard to implement as a separate function.
 

SerraAvenger

Cuz I can
Reaction score
234
Seems to do what it's supposed to do.
Prevents threads from running a critical section more than one at a time.
If there's real multithreading, it doesn't.
Code:
// A
while (#PARAM(lock)) {
    Wait(1.0, c_timeGame);
}

// B
#PARAM(lock) = true;
#SUBFUNCS(actions)
#PARAM(lock) = false;
Thread 1, 2

1A
2A
=> 1B, 2B parallel => FAIL.

Were you expecting a queue behaviour for the next thread to go in? It shouldn't be hard to implement as a separate function.

No, I was expecting a thread-safe semaphore.
 
Reaction score
54
You mean that... #PARAM(lock) is originally false, thread 1 clears the while condition, a context switch occurs before thread 1 can set #PARAM(lock) to true, thread 2 clears the while condition and now both are inside the critical section?

Yeah, that would suck. However, we are assuming that context switches may occur at any time. Perhaps Blizzard implemented it in a way that context switches only occur on waits? But it wouldn't be real multithreading then...
 

SerraAvenger

Cuz I can
Reaction score
234
Yeah, that would suck. However, we are assuming that context switches may occur at any time. Perhaps Blizzard implemented it in a way that context switches only occur on waits? But it wouldn't be real multithreading then...

That's exactly what I was saying =)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top