this post was submitted on 23 Apr 2024
686 points (95.1% liked)

Programmer Humor

31224 readers
50 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] -5 points 2 months ago (7 children)

Lol at all of the people not getting it. Why comment here at all ๐Ÿ˜…

[โ€“] [email protected] 37 points 2 months ago (5 children)

Why comment here at all

Because we're programmers, and programmers are infamous for being rules-/logic-driven.

If, as a comment below suggests, the joke is that it's meant to be read in order 3, 1, 2, that violates the rule that race conditions typically don't cause an entirely different program to produce the output. So if the joke is meant to be "lol we have a race condition", bubbles should be mixed up for one person, not mixed between people.

People don't get the joke because the joke violates its own internal rules.

[โ€“] [email protected] 11 points 2 months ago

It doesn't violate any rules.. Imagine both the "speaker" and the "text" are being updated by separate threads. A program that would eventually display the behavior in this meme is simple, and I'm a bit embarrassed to have written it because of this comment:

#include <pthread.h>
#include <stdio.h>

char* speakers[] = {
    "Alice",
    "Bob"
};
int speaker = 0;

void* change_speaker(void* arg)
{
    (void)arg;

    for (;;) {
        speaker = speaker == 0 ? 1 : 0;
    }
}

char* texts[] = {
    "Hi Bob",
    "Hi Alice, what's up?",
    "Not much Bob",
};
int text = 0;

void* change_text(void* arg)
{
    (void)arg;
    for (;;) {
        switch (text) {
        case 0:
            text = 1;
            break;
        case 1:
            text = 2;
            break;
        case 2:
            text = 0;
            break;
        }
    }
}

int main(int argc, char* argv[])
{
    pthread_t speaker_swapper, text_swapper;

    pthread_create(&text_swapper, NULL, change_text, NULL);
    pthread_create(&speaker_swapper, NULL, change_speaker, NULL);
    for (int i = 0; i < 3; ++i) {
        printf("%s: %s\n", speakers[speaker], texts[text]);
    }
}
load more comments (4 replies)
load more comments (5 replies)