I would choose threads over process, unless threads is not available, which is not (no longer) the case in Perl. When both threads and process can provide concurrent programming, why threads over process? my two-penny answer:
- Create process is expensive.
- It takes time. A call into OS is needed. If it triggers process rescheduling, OS context-switching will be involved.
- It takes memory. The entire process would be replicated.
- Interprocess communication and synchronization is also quite expansive.
- Threads can be created without replicating entire process. Some, if not all, of the work of creating threads is done in user space rather than kernal space. Threads can be synchronized by just monitoring a variable -- in other words, in user address space of the program. When process synchronize, it usually involves expansive operations trapping into kernel.
- Better performance.