how to run each thread on other core?

后端 未结 3 1499
后悔当初
后悔当初 2021-01-23 13:10

I have a udp server that receive data and computing it.

I have two thread for each role.

In my cpu is a 8 multi-core and I send data in varius speed.

but

3条回答
  •  终归单人心
    2021-01-23 13:58

    The scheduler will deal with where your threads etc will run. This is OS specific, therefore if you want to attempt to alter how code is run you would need an OS specific API that lets you set a threads affinity etc.

    Also, depends what you application is like, its a client server by the looks of it, so its not totally CPU bound. How many threads do you have in total, you mention 2 per role? A thread can only be run on one CPU. Try make units of work that can truly run in parallel, that way they can be truly run independently, ideally on different cores.

    The OS will generally do a good job of running your code since it will have a better overall picture.

提交回复
热议问题