使用全球静音的做法是不好的做法吗?

发布于 2025-02-09 05:23:15 字数 131 浏览 1 评论 0原文

我在一个程序中有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文