I am reading a book that compares two ways of implementing threads, Middleware Threads and OS Threads. I don’t know what the meaning of these sentences are exactly:
“A difficulty of operating system multithreading, however, is performance overhead. Since it is the operating system that is involved in switching threads, this involves system calls. These are generally more expensive than thread operations executed at the user level, which is where the transactional middleware is operating.”
and What is the relation of system calls and performance?
I am reading a book that compares two ways of implementing threads, Middleware Threads
Share
The book is probably a bit dated, middleware threads (aka fibers) were popular about 10 years ago. Yes, context switches are relatively expensive, somewhere between 2000 and 10,000 CPU instructions. They require a kernel transition and acquiring a global lock. User threading can avoid a large portion of that cost, only the CPU state needs to be switched.
But that doesn’t come for free:
The latter issue is the big one, blowing the cache is really expensive. CPU cores have become so fast compared to memory that the cost of trashing the cache becomes comparable to an OS context switch. And getting a lot of CPU cores is cheap.