使用全球静音的做法是不好的做法吗?
我在一个程序中有4个线程(除主线程),以执行一些文件I/O。他们都读/写入同一文件,所以我想宣布互斥品将它们同步为Main之外的全局变量,以免将同一静音传递到每个线程的功能上。这是否被认为是不良的练习,我应该将MUTEX传递给每个线程执行的函数吗?
I have 4 threads in a program (besides the main thread) that do some file I/O. They all read/write to the same file, so I thought of declaring a mutex to synchronize them as a global variable outside of main to avoid having to pass the same mutex around to each thread's function. Is this considered bad practice and should I instead pass the mutex to the function that each thread executes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论