简体   繁体   中英

C parallel thread vs parallel process

I have small c program that use lot of cpu , this program compiled to exe , and I run it as a process from my c# gui.

When I want to run it parallel on all over my cpu cores ,I have 2 options.

I have 4 cpu cores.

  1. Run this c exe from my c# as 4 process so my os seperate those process 1 for each core .

  2. Edit my c code so it run 4 thread so os will seperate 1 thread for each core, and from c# I will run it as 1 process.

Which way will be faster?

Edit: those processes/ thread will run like 3-5 houres ,and dont need to communicate between anotger thread/ process.

All of this running on windows

Running 4 threads in C will be faster than running 4 processes in C#.

There is a higher penalty for switching between processes than for switching between threads and communication between processes is slower than between threads.

Allocate a process require more time that allocate a thread, because threads share the resources (code, data...)

If your cpu continuously change processes (this usually happens) is not better solution using the processes, using of thread is more efficent and specially with a single cpu systems...

https://stackoverflow.com/a/200543/3476815

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM