什么是“知道的东西”当在C ++中潜入多线程编程时 [英] What are the "things to know" when diving into multi-threaded programming in C++

查看:133
本文介绍了什么是“知道的东西”当在C ++中潜入多线程编程时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用C ++中的无线网络应用程序,它正要到一个点,我想要在一个进程下的多线程软件,而不是将它们全部在单独的进程。理论上,我理解多线程,但我还没有潜水。

I'm currently working on a wireless networking application in C++ and it's coming to a point where I'm going to want to multi-thread pieces of software under one process, rather than have them all in separate processes. Theoretically, I understand multi-threading, but I've yet to dive in practically.

在C ++中编写多线程代码时,每个程序员应该知道什么?

What should every programmer know when writing multi-threaded code in C++?

推荐答案

我将专注于设计尽可能多的分区,所以你有最小的共享事情跨线程。如果你确定你没有在线程之间共享静态和其他资源(除了那些你会共享,如果你用流程而不是线程设计),你会很好。

I would focus on design the thing as much as partitioned as possible so you have the minimal amount of shared things across threads. If you make sure you don't have statics and other resources shared among threads (other than those that you would be sharing if you designed this with processes instead of threads) you would be fine.

因此,虽然是的,你必须牢记锁,信号量等概念,解决这个问题的最好方法是尽量避免它们。

Therefore, while yes, you have to have in mind concepts like locks, semaphores, etc, the best way to tackle this is to try to avoid them.

这篇关于什么是“知道的东西”当在C ++中潜入多线程编程时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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