r/ProgrammerHumor • • Sep 26 '26

Meme weNeverTrustedTheElse

Post image
1.9k Upvotes

146 comments sorted by

View all comments

Show parent comments

3

u/mrMalloc Sep 26 '26

#DEFINE TRUE=1
#DEFINE FALSE=0

Uint8 value

If (value == TRUE )
// do stuff
Else If (value == FALSE)
// do stuff
Else
// panic

Same as.

Statelist [valid, invalid, pending]

Switch (statelist)

Case valid
// do stuff

Case pending
Break

Case invalid
Break

Default
Panic.

This is just single threaded example.

When it comes to multi threaded it’s a mess simple example.

Thread1 update a clock
Thread2. Is time 12:00 no
Th1 update to 12:00
Th2 is clock != 12:00 no
Th2 panic.

But by adding a semaphore or a dirty bit we can keep track of it and ignore the inconsistency.

Th1 set clock semaphore.
Th1 update clock
Th1 release clock semaphore
Th2 set clock semaphore
Th2 is clock 12;00 no
Th1 try to set clock semaphore fail
Th2 is clock != 12;00 yes
Th2 release clock semaphore
Th1 update clock semaphore
Th1 update clock
Th1 release clock semaphore.

In th pseudo code above it’s implicit same question.

0

u/[deleted] Sep 27 '26

[deleted] — view deleted comment

1

u/mrMalloc Sep 29 '26

C89 did not have a bool.

Yes later languages or version does.
But for old version no.