Few questions about concurrency

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 27 00:30:20 PDT 2016


Hello! I am still attempt to better understand how concurrency 
works. I read a lot of info but still misunderstood some 
key-points.
Here is my thought about it and questions:

1. There is OS threads. Context-switching is very expensive 
because during it we should to save ALL CPU registers to RAM. 
Accessing to RAM is slowly up 200-300 times then accessing to 
registers, so dumping/restoring registers take a lot of time. 
Right?
1.1 During context-switching OS is go to kernel-mode (ring-0). I 
have heard opinion that it's cost a lot, but can't understand is 
it true and why it cost a lot?

2. Message passing is superstructure of threads. Right? When it 
can be helpful? Any user-case please.
2.1 Can simple threads pass data/messages to each other without 
message passing?

3. Fibers is threads that works in user-mode (rather in single 
kernel-thread OS do not see them, it see only 1 own Thread).
3.1 Fibers are switch explicitly. If do not call yield 
mother-thread will be hang on.
3.2 Where fibers store CPU register state in moment of switching 
between fibers? In memory? But then what difference with 
context-switching (that take a lot of time to save/restore 
registers state)?

Please correct me where I am wrong and highlight where I am right.


More information about the Digitalmars-d-learn mailing list