Frequency limit of writing to shared memory?

萝らか妹 提交于 2019-12-08 06:18:57

问题


Single threaded application (C++) continuously locks, writes and unlocks shared memory - four times a second (the loop is programically set to run once a second and there are 4 writes in the loop and no reads).

EnterCriticalSection(cs);
WriteToSharedMem();
LeaveCriticalSection(cs);

Another application (C) will access this shared memory once every few minutes.

Are there any problems with writing to shared memory at this rate?

Windows XP
C++


回答1:


At this rate there definitely not! This is extremely slow, however I'm not sure Critical section is what you want to use, the way I remember it that only ensures thread safety, not cross-application safety, you should look for something else to lock shared memory. You have to use some Inter-Process Communication (IPC) mechanism to ensure atomic operations with shared memory.




回答2:


The rate you give (four times a second) won't cause a problem, but you can't use critical sections across processes. You need a kernel level synchronization object like a mutex.




回答3:


Not at all. You can get/release the lock thousands (or tens or hundreds of thousands) of times per second. You could easily do a quick benchmark to see.



来源:https://stackoverflow.com/questions/12468126/frequency-limit-of-writing-to-shared-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!