News for hackers. Stuff that matters.
Re:Google Bard now open to use by devnull3 on Wednesday May 10, 2023 @03:18PM (#35892136)
I tried:

Question/Task: Write a lock implementation in Rust

I got this (lol):

    use std::sync::Mutex;

    struct Lock {
        mutex: Mutex<()>,
    }

    impl Lock {
        fn new() -> Lock {
            Lock {
                 mutex: Mutex::new(()),
            }
        }

        fn lock(&self) -> MutexGuard<()> {
            self.mutex.lock().unwrap()
        }

        fn unlock(&self) {
            self.mutex.unlock();
        }
    }
Re:Google Bard now open to use by mden on Wednesday May 10, 2023 @04:24PM (#35892975)
I mean, it's not really wrong, is it? :D Have you tried the same with gpt4?
Re:Google Bard now open to use by int_19h on Wednesday May 10, 2023 @07:03PM (#35894675)
GPT-4 also reaches out for Mutex. Which I think is fair - it really is the easiest way to solve the literal problem presented to it, after all.

OTOH given "write a lock implementation in Rust without using existing standard library synchronization primitives", both try to implement a spinlock. But GPT-4 knows about compare_and_swap, whereas Bard appears to believe that spinning on load(SeqCst) followed by store(SeqCst) is sufficient to synchronize with other threads.

But a task like that is more likely to depend at how much Rust code each model was trained on rather than its capability to reason.