由于C++的枚举不像C#中的枚举,其枚举类型名并不是标识符的一部分,因此经常可能发生命名冲突的问题,解决的方法有四个:在枚举元素名称前加限定前缀(如enum EnumFruit { EnumFruit_apple = 1 };),将枚举类型放在一个同名的命名空间中,或将枚举作为类的嵌套类型,或者使用C++11的enum class(What’s an enum class and why should I care?)。
Transactions are widely used in database development, especially when a database supports an application where a lot of correlated changes are needed. A transaction is a group of SQL statements that are all committed together (all changes done by these statements become a permanent part of the database) or none of these statements are committed (all these changes are rolled back). More often statements included in transaction are DML (Data Manipulation Language) statements, such as INSERT, UPDATE, DELETE and so on. But what about DDL (Data Definition Language) statements? Is it possible to include DDL commands such as CREATE, ALTER, DROP, etc., in a transaction? In this tip we are going to answer these questions for both - MS SQL Server and Oracle databases.
Solution
The approaches to use DDL commands within transactions are quite different in Microsoft SQL Server vs. Oracle. Let’s discuss this for each RDBMS separately.
图2下方是排名第一的8864号线程的更多数据,其中的Kernel和User分别是内核态净时间(23秒多)和用户态净时间(1分23秒多)。Context Switches是用户态和内核态之间切换的次数,高达3千1百多万次。左下角的Cycles是CPU执行该线程时所用的总时钟个数,7万多亿个。今天的x86处理器使用的超标量架构有4个发射端口,每次可以发出四条指令乱序执行,这意味着每个时钟周期可能执行多达四条指令。对于比较差的情况,平均每条指令所用的时钟周期(即所谓的CPI指标,Cycles Per Instruction)可能为3。按CPI为3来折算一下,CPU在这个线程上执行的指令数多达2万多亿条。2万多亿条指令是什么概念呢?曾经轰动信息产业的著名CIH病毒,总指令数只有几百条。即使按1千条来说,那么2万多亿条指令相当于把CIH病毒执行了20多亿次。
当然,这个代码在不支持static local variable thread-safe init的编译器上,是没有办法保证线程安全的,c++11标准已经规定static local variable只会被初始化一次了,然而vs2013还没有实现,vs2015里才支持了这条标准.不过这条代码在我们的程序里只有一个线程访问,所以也就不存在线程安全的问题.