multithreading - Fork and Threads in ruby -
i running program on machine 2 processors, when fork child created native thread or green thread/coroutine. child running concurrently parent or parallel?
the working of fork() in general generate new, independent process, duplicate page table, , mark pages owned process called fork() copy-on-write in process. then, fork() returns in both processes (the return value lets respective process know 1 is).
on system more 1 processor (or processor cores) can normally (assuming have smp-enabled system, cpu affinity doesn't prevent it) expect 2 processes use both processors, not strictly have guarantee.
threads generated in same way on systems (e.g. linux) exception pages owned first process not marked copy-on-write, instead owned both processes afterwards (they use same page table). on other systems, threads may implemented differently, e.g. in user land, in case not benefit multiple cpus threads.
as side note, disadvantage of using fork() , running 2 processes instead of threads processes not share common address space, means tlb must flushed on context switch.
Comments
Post a Comment