惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 风语者

一些杂项资料 今天遇到的一个奇怪的vb.net问题 asp.net页面请求实现过程 中国人的成功十要 《.net组件开发第2版》下载 IE7.0(beta)可以下载了 Google Talk中的小秘密 - 风语者 - 博客园 今天的microsoft,明天的google C# 代码标准 .NET2.0版(七)Security 编码指导方针 C# 代码标准 .NET2.0版(六)Remoting 编码指导方针 C# 代码标准 .NET2.0版(五)序列化Serialization 编码指导方针 C# 代码标准 .NET2.0版(三)项目设置和结构 C# 代码标准 .NET2.0版(二)编码惯例和约定 C# 代码标准 .NET2.0版(一)命名和风格 一些很少用到但还不错的Html功能 - 风语者 - 博客园 常见程序进程(转载) Google提供的好工具 关于Response.ContentType 合并数据记录的问题
C# 代码标准 .NET2.0版(四)多线程编码指导方针
风语者 · 2005-08-22 · via 博客园 - 风语者

1.Use synchronization domains. Avoid manual synchronization, because that often leads to deadlocks and race conditions.

2.Never call outside your synchronization domain.

3.Manage asynchronous call completion on a callback method. Do not wait, poll, or block for completion.

4.Always name your threads:

Thread currentThread = Thread.CurrentThread;
string threadName = "Main UI Thread";
currentThread.Name = threadName;

The name is traced in the debugger Threads window, making debug sessions more productive.

5.Do not call Suspend( ) or Resume( ) on a thread.

6.Do not call Thread.Sleep( ), except in the following conditions:

 a.Thread.Sleep(0) is an acceptable optimization technique to force a context switch.

 b.Thread.Sleep( ) is acceptable in testing or simulation code.

7.Do not call THRead.SpinWait( ).

8.Do not call Thread.Abort( ) to terminate threads. Use a synchronization object instead to signal the thread to terminate.

9.Avoid explicitly setting the thread priority to control execution. You can set the thread priority based on task semantics (such as ThreadPriority.BelowNormal for a screensaver).

10.Do not read the value of the ThreadState property. Use Thread.IsAlive( ) to determine whether the thread is dead or alive.

11.Do not rely on setting the thread type to background thread for application shutdown. Use a watchdog or other monitoring entity to deterministically kill threads.

12.Do not use the thread local storage unless thread affinity is guaranteed.

13.Do not call Thread.MemoryBarrier( ).

14.Never call Thread.Join( ) without checking that you are not joining your own thread:

void WaitForThreadToDie(Thread thread)
{
   Debug.Assert(Thread.CurrentThread.ManagedThreadId != thread.ManagedThreadId);
   thread.Join( );
}

15.Always use the lock( ) statement rather than explicit Monitor manipulation.

16.Always encapsulate the lock( ) statement inside the object it protects:

public class MyClass

   public void DoSomething( ) 
   {
      lock(this)
      {...}
   }
}

17.You can use synchronized methods instead of writing the lock( ) statement yourself.

18.Avoid fragmented locking.

19.Avoid using a Monitor to wait or pulse objects. Use manual or auto-reset events instead.

20.Do not use volatile variables. Lock your object or fields instead to guarantee deterministic and thread-safe access. Do not use THRead.VolatileRead( ), Thread.VolatileWrite( ), or the volatile modifier.

21.Avoid increasing the maximum number of threads in the thread pool.

22.Never stack lock( ) statements, because that does not provide atomic locking:

MyClass obj1 = new MyClass( );
MyClass obj2 = new MyClass( );
MyClass obj3 = new MyClass( );

//Do not stack lock statements
lock(obj1)
lock(obj2)
lock(obj3)
{
   obj1.DoSomething( );
   obj2.DoSomething( );
   obj3.DoSomething( );
}

Use WaitHandle.WaitAll( ) instead.