点滴线程(笔记)

多线程:多个线程同步执行,完成一件事或者多件事。工作方式:不同线程根据执行顺序共享CPU中的时间片段资源来处理程序。

线程等待:线程根据执行优先级访问资源,在释放某个资源之前,其他线程只能排队等待资源的释放。

线程同步:也就是多个线程之间的执行顺序关系。

如何实现多线程跨线程访问安全?上一段简单的代码,还是一个单例模式咯?

 1    public class DataInfo
 2     {
 3         private static DataInfo _current;
 4         private static readonly object _synLock = new object();//线程锁
 5         public static DataInfo Current
 6         {
 7             get {
 8                 if (_current == null)
 9                 {
10                     lock (_synLock)
11                     {
12                         if (_current == null)
13                         {
14                             _current = new DataInfo();
15                         }
16                     }
17                 }
18                 return _current; 
19             }
20         }
21 }

 --2011 to write notes

posted @ 2013-08-12 12:13  逐鹿天下  阅读(532)  评论(0编辑  收藏  举报