命名为主题约定? [英] Naming conventions for threads?

查看:104
本文介绍了命名为主题约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有帮助的名字线程,以便可以理清哪些线程正在做的事情为诊断和调试。

It's helpful to name threads so one can sort out which threads are doing what for diagnostic and debugging purposes.

是否有线程特定的命名约定一个沉重多线程应用程序,工作比另一种更好?任何指引?应该进入名称为线程什么样的信息?你有什么了解你的命名线程可以帮助他人?

Is there a particular naming convention for threads in a heavily multi-threaded application that works better than another? Any guidelines? What kind of information should go into the name for a thread? What have you learned about naming your threads that could be helpful to others?

推荐答案

还有据我所知,还没有标准。在时间我发现这些准则是有帮助的:

There's to my knowledge no standard. Over the time I've found these guidelines to be helpful:


  • 使用短名称,因为他们不使行日志文件太长。

  • Use short names because they don't make the lines in a log file too long.

创建名,其中重要的部分是开头。登录图形用户界面的观众往往有列的表,而线程列通常是小型或将变小由你读一切。

Create names where the important part is at the beginning. Log viewers in a graphical user interface tend to have tables with columns, and the thread column is usually small or will be made small by you to read everything else.

不要用线在线程的名字,因为这是显而易见的。

Do not use the word "thread" in the thread name because it is obvious.

使线程的名字很容易的grep-能。避免类似的冠冕堂皇的线程名称

make the thread names easily grep-able. Avoid similar sounding thread names

如果你有同样性质的几个线程,列举他们所特有的应用程序的一个执行或一个日志文件的ID ,两者适合你的日志的习惯。

if you have several threads of the same nature, enumerate them with IDs that are unique to one execution of the application or one log file, whichever fits your logging habits.

避免像的WorkerThread(你怎么命名,未来5工作者线程),GUIThread(这GUI概括?它是一个窗口吗?一切?)或计算(这是什么计算?)。

avoid generalizations like "WorkerThread" (how do you name the next 5 worker threads?), "GUIThread" (which GUI? is it for one window? for everything?) or "Calculation" (what does it calculate?).

如果你有一个测试组使用线程名与grep应用程序的日志文件,经过一段时间后不要重命名你的线程。您的测试人员会恨你这样做。在经过充分测试的应用程序线程的名字应该在那里留下来。

if you have a test group that uses thread names to grep your application's log files, do not rename your threads after some time. Your testers will hate you for doing so. Thread names in well-tested applications should be there to stay.

当你有一个服务的网络连接线,尝试包括在目标网络地址线程名称(如channel_123.212.123.3)。如果有在同一主机的多个连接不要忘记枚举虽然。

when you have threads that service a network connection, try to include the target network address in the thread name (e.g. channel_123.212.123.3). Don't forget about enumeration though if there are multiple connections to the same host.

如果您有多个线程,忘了名字,您的日志机制应该输出一个唯一的线程ID,而不是(API特有的,例如,通过调用pthread_self())

If you have many threads and forgot to name one, your log mechanism should output a unique thread ID instead (API-specific, e.g. by calling pthread_self() )

这篇关于命名为主题约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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