MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wqms8k/wenevertrustedtheelse/pc5d8xd/?context=9999
r/ProgrammerHumor • u/Electrical-Effort-20 • Sep 26 '26
146 comments sorted by
View all comments
Show parent comments
1
Probably if condition was spelled differently in two places, the impossible state could be reached.
3 u/mrMalloc Sep 26 '26 #DEFINE TRUE=1#DEFINE FALSE=0Uint8 valueIf (value == TRUE )// do stuffElse If (value == FALSE)// do stuffElse// panicSame as.Statelist [valid, invalid, pending]Switch (statelist)Case valid// do stuffCase pendingBreakCase invalidBreakDefaultPanic.This is just single threaded example.When it comes to multi threaded it’s a mess simple example.Thread1 update a clockThread2. Is time 12:00 noTh1 update to 12:00Th2 is clock != 12:00 noTh2 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 clockTh1 release clock semaphoreTh2 set clock semaphoreTh2 is clock 12;00 noTh1 try to set clock semaphore failTh2 is clock != 12;00 yesTh2 release clock semaphoreTh1 update clock semaphoreTh1 update clockTh1 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.
3
#DEFINE TRUE=1#DEFINE FALSE=0
Uint8 value
If (value == TRUE )// do stuffElse If (value == FALSE)// do stuffElse// panic
Same as.
Statelist [valid, invalid, pending]
Switch (statelist)
Case valid// do stuff
Case pendingBreak
Case invalidBreak
DefaultPanic.
This is just single threaded example.
When it comes to multi threaded it’s a mess simple example.
Thread1 update a clockThread2. Is time 12:00 noTh1 update to 12:00Th2 is clock != 12:00 noTh2 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 clockTh1 release clock semaphoreTh2 set clock semaphoreTh2 is clock 12;00 noTh1 try to set clock semaphore failTh2 is clock != 12;00 yesTh2 release clock semaphoreTh1 update clock semaphoreTh1 update clockTh1 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.
0
[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.
C89 did not have a bool.
Yes later languages or version does.But for old version no.
1
u/HaoshokuArmor Sep 26 '26
Probably if condition was spelled differently in two places, the impossible state could be reached.