News for hackers. Stuff that matters.
Re:Threads Are a Bad Idea for Most Purposes (1995) [pdf] by rovolo on Tuesday January 28, 2020 @04:14PM (#22174086)
Personally, my issues with threads and the various locks is that you have to manually manage resource ownership. It's kind of like programming without types, with manual memory management, or with null values. It's easy to program with 'null' if you do it every day, but it wears on you and there's always the chance that you make a dumb mistake. Moving that functionality into the type system is a relief because you can lean on the compiler to tell you when you're doing it wrong.

I like promises/futures because they tell me when resources will take a while to become available without blocking. I generally don't want to need to know that I need to lock the foo queue before consuming from the queue. I would rather have the queue handle that for me and encode the behavior I want in the type signature:

    next() -> T           sync, blocking
    poll() -> Optional<T> sync, non-blocking
    next() -> Future<T>   async

There are no comments on this comment yet.