memcpy是过程安全的吗? [英] Is memcpy process-safe?

查看:131
本文介绍了memcpy是过程安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了网上,却无法回答自己.

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

memcpy线程安全吗? (在Windows中)

Is memcpy threadsafe? (in Windows)

我的意思是,如果我使用单个memcpy写入进程之间共享的内存区域(使用boost :: shared_memory_object),然后尝试从另一个内存中读取该区域 使用单个memcpy的进程,则将自动阻止一个进程 在写的时候?我在哪里可以读到?

What I mean is if I write to an area of memory shared between processes (using boost::shared_memory_object) using a single memcpy and then try read that area from another process using a single memcpy then will one process be blocked automatically while that write is happening? Where can I read about this?

推荐答案

memcpy通常是针对原始速度进行编码的.这将不是线程安全的.如果需要,则需要在关键部分内执行memcpy调用或使用其他信号量机制.

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);

这篇关于memcpy是过程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆