Is it safe for multiple threads to call the same function?

后端 未结 5 1477
[愿得一人]
[愿得一人] 2020-12-15 18:00

Is it safe to for example do:

void AddTwo(int &num)
{
  num +=2;
}


void ThreadProc(lpvoid arg)
{
AddTwo((int)arg);

}

Would it be saf

5条回答
  •  无人及你
    2020-12-15 18:48

    The function itself is safe to call. It becomes dangerous if they're all trying to operate on the same variable.

提交回复
热议问题