当前位置:网站首页>C# 之 volatile关键字解析
C# 之 volatile关键字解析
2022-07-29 07:44:00 【InfoQ】
一,概念解释
二,修饰类型
- 引用类型。
- 简单类型,如sbyte、byte、short、ushort、int、uint、char、float 和 bool。
- 具有以下基本类型之一的 enum 类型:byte、sbyte、short、ushort、int 或 uint。
- 已知为引用类型的泛型类型参数。
- IntPtr 和 UIntPtr。
三,实际运用
/// <summary>
/// 单例
/// </summary>
class Singleton
{
private static Singleton _ins;
public static Singleton Instance
{
get
{
if (_ins == null)
{
_ins = new Singleton();
}
return _ins;
}
}
// 私有化构造
private Singleton() { }
}
if (_ins == null) /// <summary>
/// 多线程单例
/// </summary>
class SingletonThread
{
private static volatile SingletonThread _ins;
private static object lockHelper = new Object { };
public static SingletonThread Instance
{
get
{
if(_ins == null)
{
lock (lockHelper)
{
if(_ins == null)
_ins = new SingletonThread();
}
}
return _ins;
}
}
// 私有化构造
private SingletonThread() { }
}
边栏推荐
- [summer daily question] Luogu p6461 [coci2006-2007 5] trik
- BeanUtils.setProperty()
- MySQL 45 讲 | 07 行锁功过:怎么减少行锁对性能的影响?
- Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
- Halcon installation and testing in vs2017, DLL configuration in vs2017
- I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
- log4qt内存泄露问题,heob内存检测工具的使用
- 工业互联网行至深水区,落地的路要怎么走?
- 技术分享| 快对讲综合调度系统
- 强连通分量
猜你喜欢

Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL

How can electronic component trading enterprises solve warehouse management problems with ERP system?

Jiamusi Market Supervision Bureau carried out special food safety network training on epidemic and insect prevention

RoBERTa:A Robustly Optimized BERT Pretraining Approach

使用自定义注解校验list的大小

Joseph Ring problem

《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
What are the principles and methods of implementing functional automation testing?

Amaze UI 图标查询

Chaos and future of domestic digital collections
随机推荐
Solve the problem that CSDN cannot publish blog due to unknown copyright
状态机dp(简单版)
Mutationobserver document learning
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
Popular cow G
The smallest positive number that a subset of an array cannot accumulate
RoBERTa:A Robustly Optimized BERT Pretraining Approach
工业互联网行至深水区,落地的路要怎么走?
【暑期每日一题】洛谷 P1601 A+B Problem(高精)
Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL
Chaos and future of domestic digital collections
MapReduce steps of each stage
Introduction to logback appender
After the access database introduces DataGridView data, an error is displayed
Cross domain problems when downloading webapi interface files
Amaze UI 图标查询
Prepare esp32 environment
Log4qt memory leak, use of heob memory detection tool
梳理市面上的2大NFT定价范式和4种解决方案
Meeting notice of OA project (Query & whether to attend the meeting & feedback details)