Compile a C program with GCC, so that it can use all cpu cores in linux

后端 未结 4 1007
孤独总比滥情好
孤独总比滥情好 2020-12-16 08:35

I have a sample C program for addition. When I compile and run it with GCC it is using only one CPU core.

Is there any way to compile a C program so that it can use

4条回答
  •  佛祖请我去吃肉
    2020-12-16 09:23

    You need to create several threads. Otherwise there is only one thread, and it runs on a single core (at a time).

    Look at a tutorial about threads, specifically pthreads, to find out how to work with threads. Or you could use the fork system call to split your program into several processes, with one thread each.

提交回复
热议问题