News for hackers. Stuff that matters.
Re:Threads Basics (2009) by sureaboutthis on Thursday January 24, 2019 @08:28AM (#18988426)
So don't, unless you need to, and then it's OK?
Re:Threads Basics (2009) by taneq on Thursday January 24, 2019 @08:39AM (#18988513)
Yes, but in many many cases where people think they need to, there's actually a simpler and safer way to do it. Too many programmers see a long running task or an unresponsive UI and immediately declare that threads are the answer, when they're almost always not.

Admittedly they're much more likely to be useful now with so many spare cores on every machine, but they're still a hammer when most problems are screws.

Re:Threads Basics (2009) by opencl on Thursday January 24, 2019 @10:42AM (#18989608)
How is anything other than threads supposed to be a solution to long-running tasks blocking the UI thread?
Re:Threads Basics (2009) by monocasa on Thursday January 24, 2019 @11:16AM (#18989975)
Which long running tasks?

Blocking IO? Switch to non blocking and events.

Long running computationally expensive work? Break it into small jobs and have your job queue be a priority queue.

At that point you're correct regardless of if you've got one thread or many servicing the queue. And generally the best way to take advantage of multiple cores os to have it be totally agnostic to the number of cores it's running on like this anyway.

Re:Threads Basics (2009) by wkz on Thursday January 24, 2019 @09:51AM (#18989121)
IHMO, threads are mostly useful for scaling a workload beyond the capacity of a single core. For all other types of concurrency problems, a single thread of execution using some kind of event loop is usually a better fit.
Re:Threads Basics (2009) by setr on Thursday January 24, 2019 @11:14AM (#18989939)
Be reluctant to use threads.
Re:Threads Basics (2009) by sureaboutthis on Thursday January 24, 2019 @03:20PM (#18992521)
"Cautious" is probably a better word. Be cautious when considering threads.