How can you find the processor number a thread is running on?

前端 未结 5 1163
我在风中等你
我在风中等你 2020-12-15 22:15

I have a memory heap manager which partitions the heap into different segments based on the number of processors on the system. Memory can only be allocated on the partitio

5条回答
  •  隐瞒了意图╮
    2020-12-15 22:46

    This design smells bad to me. You seem to be making the assumption that a thread will stay associated with a specific CPU. That is not guaranteed. Yes, a thread may normally stay on a single CPU, but it doesn't have to, and eventually your program will have a thread that switches CPU's. It may not happen often, but eventually it will. If your design doesn't take this into account, then you will mostly likely eventually hit some sort of hard to trace bug.

    Let me ask this question, what happens if memory is allocated on one CPU and freed on another? How will your heap handle that?

提交回复
热议问题