Is memcpy process-safe?

前端 未结 4 1081
执笔经年
执笔经年 2020-12-16 03:54

Ive looked online and have not been able to satisfy myself with an answer.

Is memcpy threadsafe? (in Windows)

What I mean is if I write to an area of memory

4条回答
  •  旧巷少年郎
    2020-12-16 04:22

    memcpy is typically coded for raw speed. It will not be thread safe. If you require this, you need to perform the memcpy call inside of a critical section or use some other semaphor mechanism.

    take_mutex(&mutex);
    memcpy(dst, src, count);
    yield_mutex(&mutex);
    

提交回复
热议问题