• 0 Posts
  • 9 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle


  • 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]);
        }
    }
    




  • I hate getting into these discussions.

    This is Arnaud Petit and Stéphanie Bodet, two professional climbers with far more experience than you. They are doing the second ascent of a 900 meter 8a on Angel Falls (Rainbow Jambaia, 31 pitches) which is about the same height as El Capitan in Yosemite National Park. Here is a story about it. You almost never plan to climb routes this long in a single day, especially not on the second ascent. They most definitely planned to sleep on the wall and brought the proper equipment. This is called big wall climbing

    Just be happy for people doing what they love and do what you love: your life will be better. We’re all motivated by different things.