The following is the simple c source code, where char x[2048]
is a global var and func1
is called by thread1
, func2
is called by thread2
:
char x[2048]={0} , y[16]={0};
void func1(){
strcpy(x,y);
}
void func2(){
printf("(%s)\n",x);
}
int main(int argc, char **argv){
strncpy(y,argv[1],sizeof(y)-1);
}
In Intel's cpu, one cache line has 64 bytes in it, so x should occupy 32 cache lines, my questions are:
while thread1
calls func1
, should all 32 cache lines available to that CPU cache until then do strcpy
? (or) compiler knows just one cache line is enough to do the job?
While thread2
call func2
, should all 32 cache lines available to that CPU cache until then do printf
? (or) compiler can identify one cache line is enough?
I suggest you read the Wikipedia page: https://en.wikipedia.org/wiki/CPU_cache
Some background:
Answer to you question:
More Info: