3 ms·
> What is so bad about threads? Why do you need co-routines? You aren't forced into sharing memory across parts of your program that have no business sharing m
by leorocky 12y ago
> What is so bad about threads? Why do you need co-routines?
You aren't forced into sharing memory across parts of your program that have no business sharing memory. In Java you can easily end up in a situation where you can look at a program and not know what thread one line is executing in versus another line in the same file. The same instance of a class may be referencing one of its property in one thread or another, and that's sharing memory across threads. A simple if statement may fail you when you share memory across threads because after the if statement checking shared memory evaluates the underlying value for that property it may have changed before the next lines after your if statement executes.
Coroutines as they exist in Go or C# help programmers write code that don't share memory across threads. Akka does this, try it, it's amazing. Java needs native support. Threads are shit. Sharing memory across threads is a nightmare.
Edit: If you're going to downvote, explain why I'm wrong.
- wcummings 12y agoCoroutines also share process space, they're just deterministic so you don't need locks as frequently. The real benefit is lower overhead in terms of memory use, creation and task switching.
- rdtsc 12y ago> You aren't forced into sharing memory across parts of your program that have no business sharing memory. I think you are confused (but I didn't downvote you, someone did and then also downvoted my post, was it you ;-) ) Anyway. Unless you use Erlang or fork OS processes you will be sharing memory between your concurrency units. So learn Erlang it will do you good http://learnyousomeerlang.com/content http://learnyousomeerlang.com/content You can build java threads with queues and that works fine. You can shoot yourself in the foot with Go or node.js (probably more so).
- eeperson 12y agoYou can also have separate heaps per thread in Java if you use a JVM that supports it, such as Avian: http://oss.readytalk.com/avian/ http://oss.readytalk.com/avian/