#What're OS thread and CPU thread?
24 messages · Page 1 of 1 (latest)
Hey, @blissful oriole!
Please remember to /close this post once your question has been answered!
Yeah, no. You can indeed have thousands of them, but if they're not designed to sleep most of the time (like most processes of an OS do) then that will be very inefficient
Indeed all processes of an OS use at least one OS thread so yeah it's designed so that you can run thousands of them in the same system all right. It's not designed so that they play well together if they all want the CPU
Hey, This is similar to a question I answered yesterday. In most cases you need to use an Executor service. Executor services can manage threads and even reuse threads. It takes all the overly complicated deadlock prone design that manually calling new thread would do.
having to call new Thread is a very rare condition
..... If they can use 100% CPU they'll still take 100% CPU
You must be really bad at concurrency 😬
I mean, I don't typically write tasks that can keep taking up 100% CPU. But if I did, that's what it's supposed to do unless you want them managed to take up less
(Yes, I work with cryptos, but they typically use a weird CPU/GPU combine where what's loaded is the GPU. And they don't use threads per se as the tasks are nonblocking as long as they're not solved)
I'm looking at it
But i'm kinda confuse about OS thread and CPU thread
I've created 8 threads that run a while loop and it used 100% CPU
But what is it mean to have thousand of os threads?
I mean i've created 8 threads with and each thread ran a while loop, but it used all 100% CPU just with 8 threads
Well yeah, as long as that's at least as many CPU cores as you have, that's what they're supposed to do
Or would you rather your computer to slack off on you?
Look at this, how can i create 2000 threads?
They mention a theoretical max number that can be created. They didn't say it would be smart to create that many
Still, if your threads can possibly wait on some locks, then they'll stop hogging the CPU for as long as they don't get the lock. That's what most programs constantly do: waiting, and why an OS can have tons of threads at the same time
This is really an electrical engineer problem. As a developer we mainly only deal with the cores on the cpu and memory management. As far as thousands of threads, youd be lucky to have 100 threads that are actually concurrent and not a millisecond apart