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

后端 未结 5 1466
[愿得一人]
[愿得一人] 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:45

    The safey depends on the value of lpvoid arg.

    If All of the args are different each other, then safe otherwise not.

    To make function call safe, Check out 'mutex'.

提交回复
热议问题