Running two threads at the same time

前端 未结 7 1824
南旧
南旧 2020-11-29 20:07

I want to know if a program can run two threads at the same time (that is basically what it is used for correct?). But if I were to do a system call in one function where it

7条回答
  •  Happy的楠姐
    2020-11-29 20:39

    Yes, they would, at least potentially, run "at the same time", that's exactly what threads are for; of course there are many details, for example:

    • If both threads run system calls that e.g. write to the same file descriptor they might temporarily block each other.

    • If thread synchronisation primitives like mutexes are used then the parallel execution will be blocked.

    • You need a processor with at least two cores in order to have two threads truly run at the same time.

    It's a very large and very complex subject.

提交回复
热议问题