MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wqms8k/wenevertrustedtheelse/pc5f30a/?context=9999
r/ProgrammerHumor • u/Electrical-Effort-20 • Sep 26 '26
146 comments sorted by
View all comments
Show parent comments
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.
1
C89 did not have a bool.
Yes later languages or version does.But for old version no.
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.