C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/zh-cnMon, 20 Jan 2020 19:17:17 GMTMon, 20 Jan 2020 19:17:17 GMT60C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2019/12/19/217042.htmlChipsetChipsetThu, 19 Dec 2019 09:22:00 GMThttp://www.598club.com/Chipset/archive/2019/12/19/217042.htmlhttp://www.598club.com/Chipset/comments/217042.htmlhttp://www.598club.com/Chipset/archive/2019/12/19/217042.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/217042.htmlhttp://www.598club.com/Chipset/services/trackbacks/217042.html???a???http://www.zhihu.com/question/39431192

??1?o?????????????-|?1?????????????????o??????????-|?????????-|?1???????????????????|?????a?????????a?????3????????????????????????????-|?1?????o??-???????a?????3?????????3??3??|????????1?????????????????a?????'???????????o???????????????-???????????????????

????a?????'???????????????|?????a?????-|???????????|?????a???????????????

?????????o???????????????????????????'?????????????o????????????????o?????????????1????????????-|?1???????????????????????

??o?????????????? VS ???????????????

?-|???????????a??1??1????????????????????????????????????????????????1?????????????????????a??-|?????????????????????????????????????????????????????????????????????????1??-?????????????

?????a?????????????-|?1??3???????'1????-|?1??3????????a?-|?1???1?3??????????'??????????-|????????a??????1?????????????????oo?2??????????3??????????2???????oo????????????????????????????????????????????????????a?????????????'?????????-??????'????????????????2?????a?o???????????????????????a????????????1?a??-|?1?????????a???a?????1???????????????????'????????????|????????

???1??|??????????????????????????????????????????????????????????2??????????a????????????????????o?????????????????????????????????????????o2?????????????1??????????????????-????????'?????????????????????????????????2???????????o????????'????????????????2?????????????????????????????????????????????o????1???|????????????????????????

??????????????o|???????????????????????????????????oo????????'???????????1?????????????'?????????????????????????a????????a?oo??????????????????????????????????????????????????????a????????????????????2?????oo???????????o?????1????

??o????o????????-|???XX??o?????? VS ????????oXX??o??????

???????????????-|????????'????????????a??|??????1??1?????????????????????1?????3?3?a??-|????o?????1???????????|??-??????????a????????????????????????????????????????-|???XX?1|???XX????????1???

?-|??????????????, ??????????????2????????

?|???????????????-|????-|????????'???????a?-|??????|??-|???XX??????????????????????'???????a?-|??????|??????oXX”???

?|?????-|Python????-|????????'???????????????????????????????'?????????????????????????????????2???????????1?????????????????-?????????????????????????????????????????o???????-?3??????o????????'????????????????1?????????1?????????????????'??????????a?????????-|????-????

?????????-|Python?????????????-??????1??????????1|?o??1?????????????????????o?????Python????????????1??????????????o???????Python??????????????????????????????AI???????????????????-??oWeb??????????1??????????o??????????Github???????o???????o?Python??????1?????????????????????o???????????a????????o?????a?????????????1'????'?????????|???Python???Python???1????o???-??o??o?????a?????????????a????????????????????????????????????????o?????????????????????????1??2?????????????????????????????

?-|???????-????1|????????a??a??????????1??????????????????????????????????????????????1???????????????????????????????????o????Reference Doc??????????o?o?????-?3??????????????????????????o??1????1?-|??????????????o??????a?????????1??????????????????????a???????????????-????????a?????????????????????????????????????????????????3????????????o?????o?beautiful soup?????o?????????o????flask?????o??????web??????????o???????????????????????o????????????????????????a??????-?????o????-?3???????o???????????1??-????o?????????????

?-|?????????????????o??o??-|????o?????1??????????????????????????o??o??????o???????1????

?????????????????????????????????????-|????????????????????????o?o?????????o????????o??????????????????????????????????1????????o?????-|?????a???????????????1??????????-|????a??????12???????a???????

??o?????????????????????????? VS ?????????????????

?-|??????????????1????????????????????1???????????????????????????????“C?-??-|??????1????o|?????????????????????????????????XX|??????a??????????????????????2??????????????????????????|???????????80??????

??????1????????????????????'???????'?-|??????????????????????????????

?12????1????-??????????o?????????????????????'??????????????

?????o????????3???????????a?????|?????????|?????????????????????????????????'???????????????????????????????????o??????o?????????o????????o????????????????????????????????????o????????

??????????????????????????????????????????????????1?-|??????????????o?????????????????????-|?1???2??????????????????????????????1???????????1????????a?????????a????1????-???????????-|?o??????????????????????????????????????????????????????????-|?1?????????????????????3???????????????????????????????????????????????-???????????????????????????????????????1?????????????????????????????????????-??????'???????????????????o??????1??'??a????????????.

??o??????: ?o????-|?1? VS ??????-|?1?

?-|??????????o???????-|?1?????????o?o???????-|?1????????????????????'?????????????????-??????|????o?????????1???????????????????????????????o??-|?1???????????????

?????????????????oo?????????????????????o??????????????3????????????????????a???-????????????????????3?????o?????????????????????????-?????????o?????????????????????????????????????????o??????????????????????o|????o??????????o|????????????o?????????????????o??????????????

??????o|????????????????????????????????o?o???????A?????????-|B?????o?o??-|???B?????????-|C??????????????-|?1?????????????????????????o????????????????????o???????????????1???

??????????????????-|?1???'???????o?????????????-|?1?????????????????????????a???????1??o???1???????????????????????????'???????????????????1???????'??????????????????

????????????????????, ?????????????????.

????????????????????????a????????????, ???????????'????????1????????????, ?|?????????|????"?o???"????-|, ??????????????????-|?1????????o????, ?????????????????????????3?????1?????????????????????????

??o????o??????????XX????1??a? VS ???XX?1????????????1??a?

linus ??????????'?a??2??? c ?-?, ???????'????????|?, ????|??'????????3???, ?????o?????? linux ??? git ????????.

linus ????a???o?????1?????????????a??????????????????????'????oo.

??????????????????????o?????????????-|???, ?-??????????????o??1????, ??????github?o??????????21?21???, ????????'????????????????.

???????????????????????????????????????????"??c?-???????o??????aXX??????, github?????http://github.com/xxxxxx”????????"?2???c".

??????????-|????????????, ???????????a??????-?????1???, ????????????3?????????????, ????????-|???????1'????', ??a????????a?1??????????1', ????1????????o???????a????1???, ????????????????star, ??????|??????', ??????, ?????, ????o?????.

??????????-|???????????, ????1???????????????1???????????, ??????1????????a?????, ???1????????????????-??a???, ?????-?-|?1??a???'???????, ??|??????????????, ???????????, ???????????o?????????.

??????????-|????????????, ????a???????????????a?oo???????, ???????????"???????o?????1?", ????????"????-|????o?????1?", ???|???????????????????????????a?, ???|????, ?1???????o????o???????'?????????1?a?????????.

??????????-|????????????, ?????985, ???????-|??, ??????????????, ?????o???????oo?2???3?3?, ??a???????-????????????oo????????, ??????a??????????????'???????????, ???????????????"??"???.

????????????-|??????????????: ?????????????????-|??????o????, ???????????????????, ????1????a?????????



Chipset 2019-12-19 17:22 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2019/12/13/217025.htmlChipsetChipsetFri, 13 Dec 2019 06:21:00 GMThttp://www.598club.com/Chipset/archive/2019/12/13/217025.htmlhttp://www.598club.com/Chipset/comments/217025.htmlhttp://www.598club.com/Chipset/archive/2019/12/13/217025.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/217025.htmlhttp://www.598club.com/Chipset/services/trackbacks/217025.htmlI Love You, China

 

江苏快三开奖结果I love my motherland, China, for the four great inventions in history, the atomic and hydrogen bomb explosions in 1960s, the Nobel Prize winners in physics, medicine and literature, the launch and return of Shenzhou spacecrafts.

 

江苏快三开奖结果I love my motherland, China, for the vast Qinghai Tibet Plateau, the beautiful mountains and rivers in Guilin, the picturesque scenery of Jiuzhai, and majestic Great Walll, the Silk Road in the past and future.

 

I love my motherland, China, for the traditional culture with a long history, the magnificent Qin terracotta warriors and horses, the catchy poems of Tang and Song dynasties, the four masterpieces that would never fade, the cadence of opera classic.

 

I love my motherland, China, for the diligent and courageous people lived here, the grand army defending the land, air and sea, the communist party taking the leadership and serving.

 

江苏快三开奖结果I love my motherland, China, for the fruits and vegetables with all varieties produced, the numerous fishes in lakes, rivers and sea, the animals with all kinds inhabited forests, jungles and grasslands.

 

江苏快三开奖结果I love my motherland, China. I wish someday in the future, I could visit Daxing’an Mountains to listen to the woods, climb up the top of Mountain Tai to watch the sunrise, row a boat on the Moon Lake.

 

I love my motherland, China. We pupils are the hopes of our country, so we must work hard to do something useful to make country great. We pupils are the future of our country, so we must work hard to study science to make our country powerful.

 

I love you, China.

 



Chipset 2019-12-13 14:21 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2019/10/16/216922.htmlChipset

?|?|?

???????????????????????a?3?3????????'????????o???????????a???????????????????o???????????o??????????????2????3??????????????(??????????3)?????????????????????o??????????o?????????????????a???????????1??'?2????????????????????????????????????????????|????????????????????????????'????????a???????????

????????????????????????a??3????oo?????????o??????????????????????????????????--???????????????(???3:?????????3??)--??????????|??-???????1??'?o????o???????--??????oo????o???

??????????

?????????????????????o?????????????????????????????????????????????????????????o????

???????????

??????????????????????1??????????'???????a??????????????????????????????????????????'????????a?????????12???o????????????????'???????o????????????-?????????????????????????????????1???????'?????????-?????????????????????????????

???o????????'?????????????????(????????????o)????330??o(100?3)?????1????????????????o????????????????????????????'??????????????????????????????????????????1????????????????????60??o(18?3)??????????????'???????????o?????????????

??????????????????1????o?????????????|??????262000???(422000????3) ?????a???|??|?????????2????a???????o???????????o?[???3????????????????o????a?3?3????????o???????????????????o??o???????????????????????????????????1?????????]????'????????????o??????a????????o?????????ao????o???40???????????????????o???3????????????????????????o????????2????????????????o?????????????????????????????????????????o????a??????

???

????????????????????o??????????-?????????'????????????????3?????o??2???????????????????????????????|?????????????????????????????????????????????????????-?????'????????2???????????????????3????????????o??????????????2???????2??'a?3??13????????'???????????????a????????????????o????'???o??????????????????????o???????????????(????????????o????????????????2??????)?????????????3?'(????????????o????????????????????o|??????????o??a??-?o?)?????????????????????|??????????|?????o?????????????????????'????????????2?????'????????????????????????????????????????[???3?????????????????-|??????????????????o?????3??????????????????????????????????????o?????????]?????????????a??o?1???????????????????o??????????-?????????-????????????o????????????o??a?????????o???

???????????

?????-????????'????????o?????????????????????????a??????????o???????????????1???

??????

??'???????????a??????????????????o?????'?o????????????????????????13??????????????????????o|1??(1?????????)???'??????o????'???????o??????|?????????????????????????|??-??o???????????o???????????????1???o?-??|??-??????????????o??|??-??2???????????o????????????????????????????????o?o???????????????o????|???????????|??-?????'????????????????????????????????????o???????????-????

???????2

???????1610?1'??????8???????????????????????????????????????????a????????????????????????????????????|???????????????1??????????????????a???????????????????????????????????????????????????????'?oo????????a?3?3????????????????'????a?3??????????????a?3?3???'?????????????????????????????o?1610?1'??????7??????????o?????????????????'??????o?????????????????????????????'??o?????????


????????????????????????????????o??????????????????????????????????????????????1??????????o?????????????????????????????oI, II, III???IV?????????????????????????3???????2????????a????oa???

??'??18????oa??-??????????????????????????????????????????????????'????????a?????????????a????-???????????1???o3????????o???????'??????????????????????????????-????????????????????3?????????oo'1????

????????????????????????????????--?????????????--??????????|??-????o?1??'????????????????????????'????oo?????[???3?????????-???????????????????????????????????????????????oo?????]???????o??????????????a??o?a??????????o?1??????o?o???????o??3??????????????1?-?????????????????????o????????o?????-?2???????????????????o??????a??o?1?1????????o????????-?o????????????????



Chipset 2019-10-16 21:40 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2018/08/27/215882.htmlChipsetChipsetMon, 27 Aug 2018 13:14:00 GMThttp://www.598club.com/Chipset/archive/2018/08/27/215882.htmlhttp://www.598club.com/Chipset/comments/215882.htmlhttp://www.598club.com/Chipset/archive/2018/08/27/215882.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/215882.htmlhttp://www.598club.com/Chipset/services/trackbacks/215882.htmlHow far I'll go?-???????o|??o????????1?????????o????????-??-???????????????o|????????????1''?????????
I've been staring at the edge of the water
Long as I can remember, never really knowing why
I wish I could be the perfect daughter
But I come back to the water, no matter how hard I try

Every turn I take, every trail I track, every path I make, every road leads back
To the place I know, where I cannot go
Where I long to be

See the line where the sky meets the sea? It calls me
And no one knows, how far it goes
If the wind in my sail on the sea stays behind me
One day I'll know, if I go there's just no telling how far I'll go

Go-oh-oh-oh-oh-oh-oh-oh-oh-oh
Go-oh-oh-oh-oh-oh-oh-oh-oh-oh
Go-oh-oh-oh-oh-oh-oh-oh-oh-oh
Go-oh-oh-oh-oh-oh-oh-oh-oh-oh

I know everybody on this island seems so happy on this island
Everything is by design
I know everybody on this island has a role on this island
So maybe I can roll with mine

I can lead with pride, I can make us strong
I'll be satisfied if I play along
But the voice inside sings a different song
What is wrong with me?

See the light as it shines on the sea? It's blinding
But no one knows, how deep it goes
And it seems like it's calling out to me, so come find me
And let me know, what's beyond that line, will I cross that line?

See the line where the sky meets the sea? It calls me
And no one knows, how far it goes
If the wind in my sail on the sea stays behind me
One day I'll know, how far I'll go


Chipset 2018-08-27 21:14 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2017/03/22/214770.htmlChipsetChipsetWed, 22 Mar 2017 09:31:00 GMThttp://www.598club.com/Chipset/archive/2017/03/22/214770.htmlhttp://www.598club.com/Chipset/comments/214770.htmlhttp://www.598club.com/Chipset/archive/2017/03/22/214770.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/214770.htmlhttp://www.598club.com/Chipset/services/trackbacks/214770.html[?????????????-????????????o??????????a???????o???'????2???????????????????????????o?????????E?????'??o???????????????????????????????]


????o?????????????????????????[???3????????????]????????????????????oo ?1?????·???o??????????????????a??3??????|??????-??o??????o?o??????3?????????o????????1????????????????????????oT??????????????????????????2??????????????????????????????o??????????????????' ?o??????·????????? ????o?????????????????????????'??????o???????T?????????o?????o????????????????????????????????????????? ?????????1·???????? ???-????????????

 

????o?????oo????????????????????????????????????[?????????]??????????2???????????????????o?????o???????????????????'??1??-?????????-????o????[???3????o?????????????3????]??o???o??1????????????????????1???????48??????????????????????????[???3????????a?????????]????????o?????????????????2???????????o?o?????o???????-?????????????????????-??????????????o?T????????????????????????oo????-??????????????????????????????????o????????????o??????????1?????????oo???????o????????-???????????????o??????????1????????????????????????-??o??????a???????????[???3???????????????]??????|??o????????????

 

??????????????????????????????????????????????[???3??????????????????????????????oo]??????????????????????????????o?????????????????????o??????2??????????????????[???3???????a????????1]???????????1??-???????????????o??1??-?????????????????????????????????????????????3???1???????3??????????·????2????????????????|???????a?o???????'????????1????o?o??????????????????????????????-|???????2???????|??????????3?????????-?????????????????????o??1??-??????????3????-????????????????-???????????o????'??o?????oo??????????3???1??????????-????????????3??1???????????o??3?????oo??????????????????

 

?2????????1?????2???????o?[???3: ??o?????????a??????????????????????o?]???????????????????oo??3????????????????????????????????1??????????????????????-????????????2?????????o?????????????????????????-|??????????o???o???????1??-?????-???????????????1????????????o????????????o??????o???o?????????????????????????o???????o?o??????a????????????????o????????????????????????????'???????????????????????????o?o??-???????????????2????????????????T??????????????'??a????????????????oo??????????????????????????????????????????????????????????????????o??????????????o???????o??o???????????????3????????????????????????????1??????o???????o??o???????oo???????????????????o?????1???????????????'?????????????????????????????

 

????????????????????oo?-???o??????a??????????????????????3???????????????????'???2?o??????1??????????????????1????-?????????????????????????????????????[???????????????????????????????????????1??-??????????????'?]??????????????a???????????????????????????o?·???o???? ??o???o??????1??????????????????1????????1?????·???o?????????3???????-?????1?????????????????????????????o???????????????????????????????????????o??a???????????????????????????[???3???????????o???????50%?????????????????]?????3????????????????o?????'???????????[???3????????o??????????????????????????????????????????????o???'???????o??????????]????????????'?o??????3?-???????1??-????????[???3????o?????????o???????o??o??????????????????????????????-????????????-??????a??1???????????????????????????????????3??????????????]????????????????????????a???????2?????-???1????????o?????????????1??????????o?o???????????????????????????a???????o?????????

 

?????????????o????????[???3????????1???????1??????????????????????????1??-???????????-??o??????????????????-?2?????-|??]??????????????????????1??????????????????2??????????????-???????a????????a??????oo??????[???3?????|??2???????a??????????a??????oo??'???????????????????????????????????o??????????????????????????????????-??????????????????????????-?]????????????????????????????????????????????a??????????????????????????o?????????????????-??o??????????????????????[???3??????o?????????????o?o??????????????????a??????oo???????]??????2??????????????1?????????????-??o?????????????????oo?????????????????o?????????????????-??????????????????????????????????????????????????????o?????????????????????'??o????????????????T?????????????????????-??o?????o??????????o??????????????????????1'????[???3??????????????????????o?????????????2????????1'???????a????1'???????????o??-???????????????????]??????o???????????'???????????????????????????????????a????-???????1???????o??????????????????????????????????1'????????????????????????????????????????????1??2?????????????

 



Chipset 2017-03-22 17:31 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2016/10/26/214357.htmlChipsetChipsetWed, 26 Oct 2016 01:01:00 GMThttp://www.598club.com/Chipset/archive/2016/10/26/214357.htmlhttp://www.598club.com/Chipset/comments/214357.htmlhttp://www.598club.com/Chipset/archive/2016/10/26/214357.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/214357.htmlhttp://www.598club.com/Chipset/services/trackbacks/214357.html
?o??a???http://sourceforge.net/p/predef/wiki/Architectures/

Architectures

Please send updates/corrections to predef-contribute.

Type Macro Description
Identification __alpha__ Defined by GNU C
Version __alpha_ev'V'__ V = Version
Identification __alpha Defined by DEC C
Identification _M_ALPHA Defined by Visual Studio
Example
CPU Macro
Alpha EV4 __alpha_ev4__
Alpha EV5 __alpha_ev5__
Alpha EV6 __alpha_ev6__

Type Macro Description
Identification __amd64__
__amd64
__x86_64__
__x86_64
Defined by GNU C and Sun Studio
Identification _M_X64
_M_AMD64
Defined by Visual Studio

Notice that can be detected by checking if the CPU uses the .

Type Macro Description
Identification __arm__ Defined by GNU C and RealView
Identification __thumb__ Defined by GNU C and RealView in Thumb mode
Version __ARM_ARCH_'V'__ V = Version

Defined by GNU C
Identification __TARGET_ARCH_ARM
__TARGET_ARCH_THUMB
Defined by RealView
Version __TARGET_ARCH_ARM = V
__TARGET_ARCH_THUMB = V
V = Version
Version __TARGET_ARCH_'VR' VR = Version and Revision
Identification _ARM Defined by ImageCraft C
Identification _M_ARM Defined by Visual Studio
Identification _M_ARMT Defined by Visual Studio in Thumb mode
Version _M_ARM = V V = Version
Identification __arm Defined by Diab
Example
CPU Macro _M_ARM
ARM 2 __ARM_ARCH_2__
ARM 3 __ARM_ARCH_3__
__ARM_ARCH_3M__

ARM 4T __ARM_ARCH_4T__
__TARGET_ARM_4T

ARM 5 __ARM_ARCH_5__
__ARM_ARCH_5E__
5
ARM 5T __ARM_ARCH_5T__
__ARM_ARCH_5TE__
__ARM_ARCH_5TEJ__

ARM 6 __ARM_ARCH_6__
__ARM_ARCH_6J__
__ARM_ARCH_6K__
__ARM_ARCH_6Z__
__ARM_ARCH_6ZK__
6
ARM 6T2 __ARM_ARCH_6T2__
ARM 7 __ARM_ARCH_7__
__ARM_ARCH_7A__
__ARM_ARCH_7R__
__ARM_ARCH_7M__
__ARM_ARCH_7S__
7

Type Macro Description
Identification __aarch64__ Defined by GNU C

Type Macro Description
Identification __bfin
__BFIN__
Defined by GNU C

Type Macro Description
Identification __convex__ Defined by GNU C
Version __convex_'V'__ V = Version
Example
CPU Macro
Convex C1 __convex_c1__
Convex C2 __convex_c2__
Convex C32xx series __convex_c32__
Convex C34xx series __convex_c34__
Convex C38xx series __convex_c38__

Type Macro
Identification __epiphany__

Type Macro Description
Identification __hppa__ Defined by GNU C
Identification __HPPA__ Defined by Stratus VOS C
Identification __hppa
Version _PA_RISC'V'_'R' V = Version
R = Revision

See also .

Example
CPU Macro
PA RISC 1.0 _PA_RISC1_0
PA RISC 1.1 _PA_RISC1_1
__HPPA11__
__PA7100__
PA RISC 2.0 _PA_RISC2_0
__RISC2_0__
__HPPA20__
__PA8000__

Type Macro Format Description
Identification i386
__i386
__i386__

Defined by GNU C
Version __i386__
__i486__
__i586__
__i686__

Defined by GNU C
Identification __i386
Defined by Sun Studio
Identification __i386
__IA32__

Defined by Stratus VOS C
Identification _M_I86
Only defined for 16-bits architectures

Defined by Visual Studio, Digital Mars, and Watcom C/C++ (see note below)
Identification _M_IX86
Only defined for 32-bits architectures

Defined by Visual Studio, Intel C/C++, Digital Mars, and Watcom C/C++
Version _M_IX86 V00 V = Version
Identification __X86__
Defined by Watcom C/C++
Identification _X86_
Defined by MinGW32
Identification __THW_INTEL__
Defined by XL C/C++
Identification __I86__
Defined by Digital Mars
Version __I86__ V V = Version
Identification __INTEL__
Defined by CodeWarrior
Identification __386
Defined by Diab

Notice that Watcom C/C++ defines _M_IX86 for both 16-bits and 32-bits architectures. Use __386__ or _M_I386江苏快三开奖结果 to detect 32-bits architectures in this case.

Notice that the Stratus VOS is big-endian on IA32, so these macros cannot be used to detect endianness if __VOS__ is set.

Example
CPU _M_IX86 __I86__
80386 300 3
80486 400 4
Pentium 500 5
Pentium Pro/II 600 6

Type Macro Format Description
Identification __ia64__
_IA64
__IA64__

Defined by GNU C
Identification __ia64
Defined by HP aCC
Identification _M_IA64
Defined by Visual Studio
Identification _M_IA64
Defined by Intel C/C++
Version _M_IA64 ?
Identification __itanium__
Defined by Intel C/C++
Example
CPU _M_IA64 (Intel C/C++)

64100

Type Macro Description
Identification __m68k__ Defined by GNU C
Version __mc'V'__
__mc'V'
mc'V'
V = Version
Identification M68000 Defined by SAS/C
Identification __MC68K__ Defined by Stratus VOS C
Version __MC'V'__ V = Version
Example
CPU Macro
68000 __mc68000__
__MC68000__
68010 __mc68010__
68020 __mc68020__
__MC68020__
68030 __mc68030__
__MC68030__
68040 __mc68040__
68060 __mc68060__

Type Macro Description
Identification __mips__
mips
Defined by GNU C
Version _MIPS_ISA = _MIPS_ISA_MIPS'V' V = MIPS ISA level
Version _R3000
_R4000
_R5900

Identification __mips Defined by MIPSpro and GNU C
Version __mips The value indicates the MIPS ISA (Instruction Set Architecture) level
Version __MIPS_ISA'V'__ V = MIPS ISA level
Identification __MIPS__ Defined by Metrowerks
Example
CPU _MIPS_ISA GNU C Macro __mips MIPSpro Macro
R2000 _MIPS_ISA_MIPS1
1
R3000 _MIPS_ISA_MIPS1 _R3000 1
R6000 _MIPS_ISA_MIPS2
2 __MIPS_ISA2__
R4000
_R4000

R4400 _MIPS_ISA_MIPS3
3 __MIPS_ISA3__
R8000 _MIPS_ISA_MIPS4
4 __MIPS_ISA4__
R10000 _MIPS_ISA_MIPS4
4 __MIPS_ISA4__

Type Macro Description
Identification __powerpc
__powerpc__
__powerpc64__
__POWERPC__
__ppc__
__ppc64__
__PPC__
__PPC64__
_ARCH_PPC
_ARCH_PPC64
Defined by GNU C
Version __ppc'V'__ V = Version
Identification _M_PPC Defined by Visual Studio
Version _M_PPC ?
Identification _ARCH_PPC
_ARCH_PPC64
Defined by XL C/C++
Version _ARCH_'V' V = Version
Version __PPCGECKO__ Gekko

Defined by CodeWarrior
Version __PPCBROADWAY__ Broadway

Defined by CodeWarrior
Version _XENON Xenon
Identification __ppc Defined by Diab
Example
CPU _M_PPC Macro XL Macro
PowerPC 440

_ARCH_440
PowerPC 450

_ARCH_450
PowerPC 601 601 __ppc601__ _ARCH_601
PowerPC 603 603 __ppc603__ _ARCH_603
PowerPC 604 604 __ppc604__ _ARCH_604
PowerPC 620 620

Pyramid 9810

Type Macro
Identification pyr

Type Macro Description
Identification __THW_RS6000 Defined by XL C/C++
Identification _IBMR2
Identification _POWER
Identification _ARCH_PWR
_ARCH_PWR2
_ARCH_PWR3
_ARCH_PWR4

Type Macro Description
Identification __sparc__ Defined by GNU C
Identification __sparc Defined by Sun Studio
Version __sparc_v8__
__sparc_v9__
Defined by GNU C
Version __sparcv8
__sparcv9
Defined by Sun Studio
Example
CPU Sun Studio Macro GNU C Macro
SPARC v8 (SuperSPARC) __sparcv8 __sparc_v8__
SPARC v9 (UltraSPARC) __sparcv9 __sparc_v9__

Type Macro Description
Identification __sh__ Defined by GNU C
Version __sh1__
__sh2__
__sh3__
__SH3__
__SH4__
__SH5__

Type Macro Description
Identification __370__
__THW_370__
Identifies

Defined by XL C/C++
Identification __s390__ Identifies

Defined by GNU C
Identification __s390x__ Identifies

Defined by GNU C
Identification __zarch__ Identifies

Defined by clang
Identification __SYSC_ZARCH__ Identifies

Defined by Systems/C

Type Macro Description
Identification _TMS320C2XX
__TMS320C2000__
C2000 series
Identification _TMS320C5X
__TMS320C55X__
C5000 series
Identification _TMS320C6X
__TMS320C6X__
C6000 series
Example
DSP Macro
C28xx _TMS320C28X
C54x _TMS320C5XX
C55x __TMS320C55X__
C6200 _TMS320C6200
C6400 _TMS320C6400
C6400+ _TMS320C6400_PLUS
C6600 _TMS320C6600
C6700 _TMS320C6700
C6700+ _TMS320C6700_PLUS
C6740 _TMS320C6740

TMS470

Type Macro
Identification __TMS470__


Chipset 2016-10-26 09:01 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2015/07/24/211364.htmlChipsetChipsetFri, 24 Jul 2015 07:45:00 GMThttp://www.598club.com/Chipset/archive/2015/07/24/211364.htmlhttp://www.598club.com/Chipset/comments/211364.htmlhttp://www.598club.com/Chipset/archive/2015/07/24/211364.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/211364.htmlhttp://www.598club.com/Chipset/services/trackbacks/211364.html江苏快三开奖结果The Power of Ten – Rules for Developing Safety Critical Code

江苏快三开奖结果Gerard J. Holzmann

江苏快三开奖结果NASA/JPL Laboratory for Reliable Software

Pasadena, CA 91109

Most serious software development projects use coding guidelines. These guidelines are meant to state what the ground rules are for the software to be written: how it should be structured and which language features should and should not be used. Curiously, there is little consensus on what a good coding standard is. Among the many that have been written there are remarkable few patterns to discern, except that each new document tends to be longer than the one before it. The result is that most existing guidelines contain well over a hundred rules, sometimes with questionable justification. Some rules, especially those that try to stipulate the use of white-space in programs, may have been introduced by personal preference; others are meant to prevent very specific and unlikely types of error from earlier coding efforts within the same organization. Not surprisingly, the existing coding guidelines tend to have little effect on what developers actually do when they write code. The most dooming aspect of many of the guidelines is that they rarely allow for comprehensive tool-based compliance checks. Tool-based checks are important, since it is often infeasible to manually review the hundreds of thousands of lines of code that are written for larger applications.

The benefit of existing coding guidelines is therefore often small, even for critical applications. A verifiable set of well-chosen coding rules could, however, make critical software components more thoroughly analyzable, for properties that go beyond compliance with the set of rules itself. To be effective, though, the set of rules has to be small, and must be clear enough that it can easily be understood and remembered. The rules will have to be specific enough that they can be checked mechanically. To put an easy upper-bound on the number of rules for an effective guideline, I will argue that we can get significant benefit by restricting to no more than ten rules. Such a small set, of course, cannot be all-encompassing, but it can give us a foothold to achieve measurable effects on software reliability and verifiability. To support strong checking, the rules are somewhat strict – one might even say Draconian. The trade-off, though, should be clear. When it really counts, especially in the development of safety critical code, it may be worth going the extra mile and living within stricter limits than may be desirable. In return, we should be able to demonstrate more convincingly that critical software will work as intended.

江苏快三开奖结果Ten Rules for Safety Critical Coding

The choice of language for a safety critical code is in itself a key consideration, but we will not debate it much here. At many organizations, JPL included, critical code is written in C. With its long history, there is extensive tool support for this language, including strong source code analyzers, logic model extractors, metrics tools, debuggers, test support tools, and a choice of mature, stable compilers. For this reason, C is also the target of the majority of coding guidelines that have been developed. For fairly pragmatic reasons, then, our coding rules primarily target C and attempt to optimize our ability to more thoroughly check the reliability of critical applications written in C.

The following rules may provide benefit, especially if the low number means that developers will actually adhere to them. Each rule is followed with a brief rationale for its inclusion.

1. Rule: Restrict all code to very simple control flow constructs – do not use goto statements, setjmp or longjmp constructs, and direct or indirect recursion.

江苏快三开奖结果Rationale: Simpler control flow translates into stronger capabilities for verification and often results in improved code clarity. The banishment of recursion is perhaps the biggest surprise here. Without recursion, though, we are guaranteed to have an acyclic function call graph, which can be exploited by code analyzers, and can directly help to prove that all executions that should be bounded are in fact bounded.

(Note that this rule does not require that all functions have a single point of return – although this often also simplifies control flow. There are enough cases, though, where an early error return is the simpler solution.)

2. Rule: All loops must have a fixed upper-bound. It must be trivially possible for a checking tool to prove statically that a preset upper-bound on the number of iterations of a loop cannot be exceeded. If the loop-bound cannot be proven statically, the rule is considered violated.

江苏快三开奖结果Rationale: The absence of recursion and the presence of loop bounds prevents runaway code. This rule does not, of course, apply to iterations that are meant to be non-terminating (e.g., in a process scheduler). In those special cases, the reverse rule is applied: it should be statically provable that the iteration cannot terminate.

江苏快三开奖结果One way to support the rule is to add an explicit upper-bound to all loops that have a variable number of iterations (e.g., code that traverses a linked list). When the upper- bound is exceeded an assertion failure is triggered, and the function containing the failing iteration returns an error. (See Rule 5 about the use of assertions.)

江苏快三开奖结果3. Rule: Do not use dynamic memory allocation after initialization.

江苏快三开奖结果Rationale: This rule is common for safety critical software and appears in most coding guidelines. The reason is simple: memory allocators, such as malloc, and garbage collectors often have unpredictable behavior that can significantly impact performance. A notable class of coding errors also stems from mishandling of memory allocation and free routines: forgetting to free memory or continuing to use memory after it was freed, attempting to allocate more memory than physically available, overstepping boundaries on allocated memory, etc. Forcing all applications to live within a fixed, pre-allocated, area of memory can eliminate many of theseproblems and make it easier to verify memory use. Note that the only way to dynamically claim memory in the absence of memory allocation from the heap is to use stack memory. In the absence of recursion (Rule 1), an upper-bound on the use of stack memory can derived statically, thus making it possible to prove that an application will always live within its pre-allocated memory means.

4. Rule: No function should be longer than what can be printed on a single sheet of paper in a standard reference format with one line per statement and one line per declaration. Typically, this means no more than about 60 lines of code per function.

Rationale: Each function should be a logical unit in the code that is understandable and verifiable as a unit. It is much harder to understand a logical unit that spans multiple screens on a computer display or multiple pages when printed. Excessively long functions are often a sign of poorly structured code.

5. Rule: The assertion density of the code should average to a minimum of two assertions per function. Assertions are used to check for anomalous conditions that should never happen in real-life executions. Assertions must always be side-effect free and should be defined as Boolean tests. When an assertion fails, an explicit recovery action must be taken, e.g., by returning an error condition to the caller of the function that executes the failing assertion. Any assertion for which a static checking tool can prove that it can never fail or never hold violates this rule. (I.e., it is not possible to satisfy the rule by adding unhelpful “assert(true)” statements.)

江苏快三开奖结果Rationale: Statistics for industrial coding efforts indicate that unit tests often find at least one defect per 10 to 100 lines of code written. The odds of intercepting defects increase with assertion density. Use of assertions is often also recommended as part of a strong defensive coding strategy. Assertions can be used to verify pre- and post-conditions of functions, parameter values, return values of functions, and loop-invariants. Because assertions are side-effect free, they can be selectively disabled after testing in performance-critical code.

A typical use of an assertion would be as follows:

江苏快三开奖结果if (!c_assert(p >= 0) == true) {

     return ERROR;

}

with the assertion defined as follows:

#define c_assert(e)    ((e) ? (true) : \

                                       tst_debugging(”%s,%d: assertion ’%s’ failed\n”, \

                                       __FILE__, __LINE__, #e), false)

江苏快三开奖结果In this definition, __FILE__ and __LINE__ are predefined by the macro preprocessor to produce the filename and line-number of the failing assertion. The syntax #e turns the assertion condition e into a string that is printed as part of the error message. In code destined for an embedded processor there is of course no place to print the error message itself – in that case, the call to tst_debugging is turned into a no-op, andthe assertion turns into a pure Boolean test that enables error recovery from anomolous behavior.

江苏快三开奖结果6. Rule: Data objects must be declared at the smallest possible level of scope.

江苏快三开奖结果Rationale: This rule supports a basic principle of data-hiding. Clearly if an object is not in scope, its value cannot be referenced or corrupted. Similarly, if an erroneous value of an object has to be diagnosed, the fewer the number of statements where the value could have been assigned; the easier it is to diagnose the problem. The rule discourages the re-use of variables for multiple, incompatible purposes, which can complicate fault diagnosis.

7. Rule: The return value of non-void functions must be checked by each calling function, and the validity of parameters must be checked inside each function.

江苏快三开奖结果Rationale: This is possibly the most frequently violated rule, and therefore somewhat more suspect as a general rule. In its strictest form, this rule means that even the return value ofprintf statements and file close statements must be checked. One can make a case, though, that if the response to an error would rightfully be no different than the response to success, there is little point in explicitly checking a return value.

江苏快三开奖结果This is often the case with calls toprintf and close. In cases like these, it can be acceptable to explicitly cast the function return value to (void) – thereby indicating that the programmer explicitly and not accidentally decides to ignore a return value. In more dubious cases, a comment should be present to explain why a return value is irrelevant. In most cases, though, the return value of a function should not be ignored, especially if error return values must be propagated up the function call chain.

Standard libraries famously violate this rule with potentially grave consequences. See, for instance, what happens if you accidentally execute strlen(0), or strcat(s1, s2, -1) with the standard C string library – it is not pretty. By keeping the general rule, we make sure that exceptions must be justified, with mechanical checkers flagging violations. Often, it will be easier to comply with the rule than to explain why non- compliance might be acceptable.

江苏快三开奖结果8. Rule:   The use of the preprocessor must be limited to the inclusion of header files and simple macro definitions. Token pasting, variable argument lists (ellipses), and recursive macro calls are not allowed. All macros must expand into complete syntactic units. The use of conditional compilation directives is often also dubious, but cannot always be avoided. This means that there should rarely be justification for more than one or two conditional compilation directives even in large software development efforts, beyond the standard boilerplate that avoids multiple inclusion of the same header file. Each such use should be flagged by a tool-based checker and justified in the code.

江苏快三开奖结果Rationale: The C preprocessor is a powerful obfuscation tool that can destroy code clarity and befuddle many text based checkers. The effect of constructs in unrestricted preprocessor code can be extremely hard to decipher, even with a formal languagedefinition in hand. In a new implementation of the C preprocessor, developers often have to resort to using earlier implementations as the referee for interpreting complex defining language in the C standard. The rationale for the caution against conditional compilation is equally important. Note that with just ten conditional compilation directives, there could be up to 210 possible versions of the code, each of which would have to be tested– causing a huge increase in the required test effort.

9. Rule: The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Pointer dereference operations may not be hidden in macro definitions or inside typedef declarations. Function pointers are not permitted.

江苏快三开奖结果Rationale: Pointers are easily misused, even by experienced programmers. They can make it hard to follow or analyze the flow of data in a program, especially by tool-based static analyzers. Function pointers, similarly, can seriously restrict the types of checks that can be performed by static analyzers and should only be used if there is a strong justification for their use, and ideally alternate means are provided to assist tool-based checkers determine flow of control and function call hierarchies. For instance, if function pointers are used, it can become impossible for a tool to prove absence of recursion, so alternate guarantees would have to be provided to make up for this loss in analytical capabilities.

10. Rule: All code must be compiled, from the first day of development, with all compiler warnings enabled at the compiler’s most pedantic setting. All code must compile with these setting without any warnings. All code must be checked daily with at least one, but preferably more than one, state-of-the-art static source code analyzer and should pass the analyses with zero warnings.

Rationale: There are several very effective static source code analyzers on the market today, and quite a few freeware tools as well.2 There simply is no excuse for any software development effort not to make use of this readily available technology. It should be considered routine practice, even for non-critical code development. The rule of zero warnings applies even in cases where the compiler or the static analyzer gives an erroneous warning: if the compiler or the static analyzer gets confused, the code causing the confusion should be rewritten so that it becomes more trivially valid. Many developers have been caught in the assumption that a warning was surely invalid, only to realize much later that the message was in fact valid for less obvious reasons. Static analyzers have somewhat of a bad reputation due to early predecessors, such as lint, that produced mostly invalid messages, but this is no longer the case. The best static analyzers today are fast, and they produce selective and accurate messages. Their use should not be negotiable at any serious software project.

The first two rules guarantee the creation of a clear and transparent control flow structure that is easier to build, test, and analyze. The absence of dynamic memory allocation, stipulated by the third rule, eliminates a class of problems related to the allocation and freeing of memory, the use of stray pointers, etc. The next few rules (4 to 7) are fairly broadly accepted as standards for good coding style. Some benefits of other coding styles that have been advanced for safety critical systems, e.g., the discipline of “design by contract” can partly be found in rules 5 to 7.

江苏快三开奖结果These ten rules are being used experimentally at JPL in the writing of mission critical software, with encouraging results. After overcoming a healthy initial reluctance to live within such strict confines, developers often find that compliance with the rules does tend to benefit code clarity, analyzability, and code safety. The rules lessen the burden on the developer and tester to establish key properties of the code (e.g., termination or boundedness, safe use of memory and stack, etc.) by other means. If the rules seem Draconian at first, bear in mind that they are meant to make it possible to check code where very literally your life may depend on its correctness: code that is used to control the airplane that you fly on, the nuclear power plant a few miles from where you live, or the spacecraft that carries astronauts into orbit. The rules act like the seat-belt in your car: initially they are perhaps a little uncomfortable, but after a while their use becomes second-nature and not using them becomes unimaginable.



Chipset 2015-07-24 15:45 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2015/04/01/210219.htmlChipsetChipsetWed, 01 Apr 2015 06:39:00 GMThttp://www.598club.com/Chipset/archive/2015/04/01/210219.htmlhttp://www.598club.com/Chipset/comments/210219.htmlhttp://www.598club.com/Chipset/archive/2015/04/01/210219.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/210219.htmlhttp://www.598club.com/Chipset/services/trackbacks/210219.html
Someone gives you a bug. "The light in the conference room on the 26th floor is on. It needs to be off."

A note on the bug says, “This will take you like 5 minutes. It's just flipping a switch."

You go to the conference room on 26. The light is on, but there's no light switch in the room.

So you prepare to install one. But the designer says it would ruin the room’s aesthetic. Plus, the walls are concrete. With the proper tools, you could install the switch. But no one will approve the purchase of the proper tools. Without the proper tools it will take two days. And they want it done now, because they're afraid that any minute the CEO might decide to go to the 26th floor and happen to walk by the conference room and ask why the hell that light is on.

And now you're getting emails asking why the light isn't off yet.

So now you have to stop and send a group email to explain the situation, and several people start up a panicked email chain.

You know if you wait for the problem to be resolved by anyone discussing it in the email chain, it won’t get fixed. The bug has your name on it, and it's dated today, so you're the one in trouble if it isn't resolved. So you go up into the hallway ceiling on 26, find the wires leading to the light, cut and cap them. Finally. Problem solved.

In order to quell the panic in the email thread, you report back how you solved the issue.

You don’t hear anything for a while. When you do, everyone is concerned that now the light can’t be turned on and off. What if the CEO wants to have a meeting in there? So here’s what they ask you to do: They want you to run wires from the light down into the basement. When someone needs the light to be on or off, they’ll contact you, and have you run to the basement and either connect or disconnect the wires.

You protest the ridiculousness of this solution. Your boss says, “Yeah, I know it’s not ideal. But it’s the only solution we have right now."

At this point you realize you have a choice. You could do this. Or you could quit in protest, and find another job. But you realize that once you start that new job, they’re likely to ask you to do something just as idiotic, if not more so.

So you go run the wires from floor 26 down to the basement. When you get to the basement, you see dozens of wires hanging out of the walls, from all the people who have had to do this exact same thing before. (So that’s where the idea came from.) You set up the wires and label them as best you can, with a short apology to whoever has to deal with this next.

When you get back to your desk, you have a message. QA has reopened the bug. It says, “I see light."

You head back up to the conference room on 26. The light is off. You go back to your desk and close the bug, reporting that you checked on it in person.

QA reopens the bug again. “Room still lit” it says. After looking at the unlit bulb one more time, you tell your boss, who suggests you go back down to the basement and check the wires. You protest that you are looking at the light right now and it’s off. “I know, but this way you can tell QA you checked out absolutely everything."

So you sigh and head to the basement. Sure enough, the wires are not connected. The ends are capped. They are not resting on anything that could conduct electricity.

You report back to QA that you checked the wires, which are not connected, and that you looked at the bulb, which was unlit.

“I didn’t mean the bulb,” says QA. “The bug is about light in the room. There’s still too much light. Shouldn’t you close the blinds?"

You respond that the blinds don’t fall under your control, and that the bug specifies the light being turned off.

Not believing you, QA sends out a group email asking if the blinds are covered by the bug.

Some time passes before you hear from anyone. Finally someone from the email chain calls you.

“Theoretically,” they ask, “could someone participating in a meeting in the conference room on 26 open or close the blinds by themselves if it was too bright or too dark?"

Yes they could, you reply.

“Like, an ordinary person? They wouldn’t need you to do it?"

Yes, an ordinary person. No, they wouldn’t need you. Anyone can do it.

“Great. Excellent. Then we’ll leave that for now. I’ll schedule a stand-up meeting about the blinds issue."

So the bug is closed. Now, the CEO, possibly having caught wind of all the discussion and furtive activity surrounding the conference room on 26, wants to have a meeting there. You get several panicked emails that they need the light on.

You go to the basement, connect the wires, and return to your desk, to find 32 new messages in your inbox. “Something’s wrong—the light’s not on!” “There’s a problem — no light!” “Are you getting these emails?” and so on.

The 32nd email says, “Nevermind—the light’s on."

This process is repeated more or less exactly when it’s time to turn the light off again.

But if there’s any good news, it’s this: after the meeting, everyone forgets that there even is a conference room on 26, so you never have to do anything about it again.

Wow, gold! Thanks!

Chipset 2015-04-01 14:39 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2014/06/15/207298.htmlChipsetChipsetSun, 15 Jun 2014 09:38:00 GMThttp://www.598club.com/Chipset/archive/2014/06/15/207298.htmlhttp://www.598club.com/Chipset/comments/207298.htmlhttp://www.598club.com/Chipset/archive/2014/06/15/207298.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/207298.htmlhttp://www.598club.com/Chipset/services/trackbacks/207298.html
 1 #ifdef __GNUC__
 2 
 3 #if (defined _WIN64 || defined __x86_64__)
 4 
 5 /**
 6  * ../bit_scan_forward
 7  * @return index (0..63) of least significant one bit
 8  */
 9 unsigned bit_scan_forward(unsigned long long x)
10 {
11    asm("bsfq %0, %0" : "=r" (x) : "0" (x));
12    return unsigned(x);
13 }
14 
15 /**
16  * bit_scan_reverse
17  * @return index (0..63) of most significant one bit
18  */
19 unsigned bit_scan_reverse(unsigned long long x)
20 {
21    asm("bsrq %0, %0" : "=r" (x) : "0" (x));
22    return unsigned(x);
23 }
24 
25 #elif (defined _WIN32) || (defined __linux__)
26 
27 /**
28  * ../bit_scan_forward
29  * @return index (0..63) of least significant one bit
30  */
31 unsigned bit_scan_forward(unsigned long long x)
32 {
33    asm("bsf %0, %0" : "=r" (x) : "0" (x));
34    return unsigned(x);
35 }
36 
37 /**
38  * bit_scan_reverse
39  * @return index (0..63) of most significant one bit
40  */
41 unsigned bit_scan_reverse(unsigned long long x)
42 {
43    asm("bsr %0, %0" : "=r" (x) : "0" (x));
44    return unsigned(x);
45 }
46 
47 #endif
48 
49 #endif


Chipset 2014-06-15 17:38 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2014/03/22/206281.htmlChipsetChipsetSat, 22 Mar 2014 07:37:00 GMThttp://www.598club.com/Chipset/archive/2014/03/22/206281.htmlhttp://www.598club.com/Chipset/comments/206281.htmlhttp://www.598club.com/Chipset/archive/2014/03/22/206281.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/206281.htmlhttp://www.598club.com/Chipset/services/trackbacks/206281.html
 1 
 2 #if (defined __unix__) || (defined _WIN64) || (defined _WIN32)
 3 #include <sys/types.h>
 4 #include <sys/stat.h>
 5 #else
 6 #include <fstream>
 7 #endif
 8 
 9 #if (defined __unix__)
10 
11 unsigned long long file_length(const char* file)
12 {
13   struct stat64 st;
14   int err = stat64(file, &st);
15   if(0 != err)
16     return 0;
17   return static_cast<unsigned long long>(st.st_size);
18 }
19 
20 #elif (defined _WIN32) || (defined _WIN64)
21 
22 // Microsoft has some extensions to support Unix!
23 unsigned long long file_length(const char* file)
24 {
25   struct __stat64 st;
26   int err = _stat64(file, &st);
27   if(0 != err)
28     return 0;
29   return static_cast<unsigned long long>(st.st_size);
30 }
31 
32 #else
33 
34 // the last alternative
35 unsigned long long file_length(const char* file)
36 {
37   std::ifstream fin(file, std::ios_base::in);
38   if(!fin.is_open())
39     return 0;
40   fin.seekg(0, std::ios_base::beg);
41   std::ifstream::pos_type pos_start = fin.tellg();
42   fin.seekg(0, std::ios_base::end);
43   std::ifstream::pos_type pos_end = fin.tellg();
44   return static_cast<unsigned long long>(pos_end - pos_start);
45 }
46 
47 #endif
48 


Chipset 2014-03-22 15:37 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2013/08/24/202745.htmlChipsetChipsetSat, 24 Aug 2013 15:46:00 GMThttp://www.598club.com/Chipset/archive/2013/08/24/202745.htmlhttp://www.598club.com/Chipset/comments/202745.htmlhttp://www.598club.com/Chipset/archive/2013/08/24/202745.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/202745.htmlhttp://www.598club.com/Chipset/services/trackbacks/202745.html  1 //&nb...  ?????????

Chipset 2013-08-24 23:46 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2013/05/25/200587.htmlChipsetChipsetSat, 25 May 2013 10:57:00 GMThttp://www.598club.com/Chipset/archive/2013/05/25/200587.htmlhttp://www.598club.com/Chipset/comments/200587.htmlhttp://www.598club.com/Chipset/archive/2013/05/25/200587.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/200587.htmlhttp://www.598club.com/Chipset/services/trackbacks/200587.html?????????

Chipset 2013-05-25 18:57 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2012/09/09/190053.htmlChipsetChipsetSun, 09 Sep 2012 14:53:00 GMThttp://www.598club.com/Chipset/archive/2012/09/09/190053.htmlhttp://www.598club.com/Chipset/comments/190053.htmlhttp://www.598club.com/Chipset/archive/2012/09/09/190053.html#Feedback6http://www.598club.com/Chipset/comments/commentRss/190053.htmlhttp://www.598club.com/Chipset/services/trackbacks/190053.html?????????

Chipset 2012-09-09 22:53 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2012/08/26/188340.htmlChipsetChipsetSun, 26 Aug 2012 08:49:00 GMThttp://www.598club.com/Chipset/archive/2012/08/26/188340.htmlhttp://www.598club.com/Chipset/comments/188340.htmlhttp://www.598club.com/Chipset/archive/2012/08/26/188340.html#Feedback6http://www.598club.com/Chipset/comments/commentRss/188340.htmlhttp://www.598club.com/Chipset/services/trackbacks/188340.html?????????

Chipset 2012-08-26 16:49 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2012/08/08/186678.htmlChipsetChipsetWed, 08 Aug 2012 11:35:00 GMThttp://www.598club.com/Chipset/archive/2012/08/08/186678.htmlhttp://www.598club.com/Chipset/comments/186678.htmlhttp://www.598club.com/Chipset/archive/2012/08/08/186678.html#Feedback7http://www.598club.com/Chipset/comments/commentRss/186678.htmlhttp://www.598club.com/Chipset/services/trackbacks/186678.html &nbs...  ?????????

Chipset 2012-08-08 19:35 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2012/01/10/163932.htmlChipsetChipsetTue, 10 Jan 2012 05:10:00 GMThttp://www.598club.com/Chipset/archive/2012/01/10/163932.htmlhttp://www.598club.com/Chipset/comments/163932.htmlhttp://www.598club.com/Chipset/archive/2012/01/10/163932.html#Feedback2http://www.598club.com/Chipset/comments/commentRss/163932.htmlhttp://www.598club.com/Chipset/services/trackbacks/163932.htmlbogo sort????stupid sort???slow sort???????????o???????????????????o?????3??o???????3??????o???????????????o?(?????????????????)??????
??????o?????3?????????3?????1?o??????a??????????o???????????o???????????????????????o?????????'???????????a?o????????o???o?-????????'??????o|??????????????????O(n)????????????????????????????????????????????O(n*n!)??????????????????????????????????????????o????
  1 // bogo_sort.hpp
  2 #ifndef BOGO_SORT_HPP_
  3 #define BOGO_SORT_HPP_
  4 
  5 template <typename ForwardIterator, typename Compare>
  6 bool is_sorted(ForwardIterator first, ForwardIterator last, Compare cmp)
  7 {
  8   if (first == last)
  9     return true;
 10   ForwardIterator next = first;
 11   for(++next; next != last; first = next, ++next)
 12     if(cmp(*next, *first))
 13       return false;
 14   return true;
 15 }
 16 
 17 template <typename T>
 18 inline void swap(T& x, T& y)
 19 {
 20   const T tmp(x);
 21   x = y;
 22   y = tmp;
 23 }
 24 
 25 template <typename RandomIterator, typename RandomGen>
 26 void shuffle(RandomIterator first, RandomIterator last, RandomGen gen)
 27 {
 28   unsigned long d = last - first;
 29   if(d < 2)
 30     return;
 31   for(RandomIterator it = first; first != last; ++first)
 32     swap(*(it + gen()%d), *first);
 33 }
 34 
 35 #include "random.hpp"
 36 
 37 template <typename RandomIterator, typename Compare>
 38 void bogo_sort(RandomIterator first, RandomIterator last, Compare cmp)
 39 {
 40   while(!is_sorted(first, last, cmp))
 41     shuffle(first, last, random());
 42 }
 43 
 44 #endif
 45 
 46 // random.hpp
 47 #ifndef RANDOM_HPP_
 48 #define RANDOM_HPP_
 49 #include <ctime>
 50 
 51 class random
 52 {
 53 private:
 54   typedef unsigned long UInt32; // ?|???????????????????????uint32_t??????unsigned long??????
 55   UInt32 a;
 56   UInt32 b;
 57   UInt32 c;
 58   UInt32 d;
 59 
 60   UInt32 randomize()
 61   {
 62     UInt32 e = a - ((b << 27| (b >> 5));
 63     a = b ^ ((c << 17| (c >> 15));
 64     b = c + d;
 65     c = d + e;
 66     d = e + a;
 67     return d;
 68   }
 69 
 70   void init()
 71   {
 72     for(UInt32 i = 0; i < 20++i)
 73       randomize();
 74   }
 75 
 76 public:
 77   explicit random(UInt32 s = std::time(0)) : a(4058668781ul), b(s), c(s), d(s)
 78   {
 79     init();
 80   }
 81 
 82   void reset(UInt32 s = 0)
 83   {
 84     if(0 == s)
 85       s = std::time(0);
 86     a = 4058668781ul;
 87     b = c = d = s;
 88     init();
 89   }
 90 
 91   UInt32 rand()
 92   {
 93   //returns a random integer in the range [0, 4294967296)
 94     return randomize();
 95   }
 96 
 97   double real()
 98   {
 99   //returns a random real number in the range [0.0, 1.0)
100     return randomize() / 4294967296.0;
101   }
102 
103   UInt32 operator()() { return rand(); }
104 };
105 
106 #endif  // RANDOM_HPP_

 1 // main.cpp
 2 #include "bogo_sort.hpp"
 3 #include <iostream>
 4 
 5 template <typename T>
 6 struct greater
 7 {
 8   bool operator ()(const T& x, const T& y) const { return y < x; }
 9 };
10 
11 int main()
12 {
13   const int LEN = 4;
14   int arr[LEN] = { 2514 };
15   while(!is_sorted(arr, arr + LEN, greater<int>())) // ??????a????????????o?o???
16     shuffle(arr, arr + LEN, random());
17   for(int i = 0; i < LEN; ++i)                              // ?o???????1???-???????o?????????
18     std::cout << arr[i] << ' ';
19 
20   return 0;
21 }
22 


Chipset 2012-01-10 13:10 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/12/21/162552.htmlChipsetChipsetWed, 21 Dec 2011 12:34:00 GMThttp://www.598club.com/Chipset/archive/2011/12/21/162552.htmlhttp://www.598club.com/Chipset/comments/162552.htmlhttp://www.598club.com/Chipset/archive/2011/12/21/162552.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/162552.htmlhttp://www.598club.com/Chipset/services/trackbacks/162552.html?????????

Chipset 2011-12-21 20:34 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/10/20/158729.htmlChipsetChipsetThu, 20 Oct 2011 01:51:00 GMThttp://www.598club.com/Chipset/archive/2011/10/20/158729.htmlhttp://www.598club.com/Chipset/comments/158729.htmlhttp://www.598club.com/Chipset/archive/2011/10/20/158729.html#Feedback2http://www.598club.com/Chipset/comments/commentRss/158729.htmlhttp://www.598club.com/Chipset/services/trackbacks/158729.html

????1'???DIY?o??????????????CPU????????????????3??????????????????AM3?3???????????1?CPU???????????o??????3???????????????????????1??????

?????????????????????????????'????1|??????????50000??????????? ??????1??????'?????????24??????????o???????1'365?????????o????????????????????????50000/24/365=5.7?1'?????????????????????o|???????13??????????4 ?????????-??????????????????3??????34?1'????????????????????a??????1/10?????????????1?????3.4?1'???????????????-??o???3?1'??????????o?????'?o??????1???3???CPU ?????????????-????1??'????????????-????2???????????????????o??????????1?1'?|??3??12?o??????|??????????1???(?|?????????????????o?????3????oCPU??????3????o?CPU?????????????????)

????????3?3???????????????1?o?????????????o???????????o????CPU????????o?????1'???????o??????Made In China????????'????????????2??3???????????????????3??????????????????????????1?????????

|??????3?????????3???????CPU?????-??????????????????????-??????????????3?????????????o???????????'???????????-??????????o??????????????????????????'??|????????????????????????-?????????????????????o???????????????a??o??????????????????????????????????????????????CPU????????-?????????-??-????????????????????????'?????????????????????????????o???|??o?

?o???????3????????-?????????-???????????????????????o???a?2???????????????-??????CPU????????????????????????????o?????????????o????????o????????????-?oo?????????????????????|???????????3???CPU????????-?????????????????????o????????????o1????????.......

????????????????????????????'????1|???Stars-922??????????????????2????????????????????1???????...-50?o|???250?o|?-?????????????????????????????Made in Taiwan?Made in China??????1??.??a???????????-???????????????1?????????????...

谷?-???????????oo???????????????????'?????????????2???????????????????o????CPU???????????-???????????????????????????????3??????????o????????|????2??????????????????

???o???????????????????????????'?????????????2?????3?????????????????????????????1??1?????????????????????-??????CPU??????3???|?a?'?o?????2??3????????????....

???????CPU????????o??????????????????????????????????????12????o??1???????????-??????CPU?????????????????????...

?????a????-????????oo?????????????o?o?????????-????|??????????????????????????????????????3?????oo?12??o??????????????

?a??????????????o????????-|????'???????????????????????-????-|?'????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????-??????????????????-???????o??o??????????1??????????????????????-????o?....
????1??????????

 

1) ?????????o??????o???????|?????????-??????????????????????????????????????????????(?1????????????????????????-???????|?)?????????????????????????????????????????????????????????-??????????-??????????o??????????1?3??????3?????????????????????????????

 

?3??????CPU?????|???????????????????????2??3?????????????????oCPU???????????'??????????????????o??????????????????????????????'??????????1???????3???????3?????????????'??1?????1????o??????????????????????????1??????

 

???????DIY????????????????????o??a?1???????????o??????(????CPU)????|?????????????-??????????-???????3??CPU????|??????????????????????????????????CPU????o??????(CPU???????????????????o??????????oo)?????????????????????????3????

 

2) |??????|????CPU???????????|??????????-?????????????????????????????????????|??????o?????|??????????a?'?o??????????????4??a?o???(???????????'??o????????????????)????????????????????|??o???????????CPU?????????????????????????????????????????1??'?????????CPU??????????|??????????????1???????????????????????????1?????????????????3?????o???????3?????????????????????1??????????o???a???|??1?2????????-????????CPU????'?????1?????????CPU????3????????????CPU?????????|????CPU????????????|????????o???????????2?o????????o?????1??????????-?????3?????CPU?????????????????2???o??????????Intel?3????????????CPU?????????|??1??????

 

?????????????????????????????????-????????????????????????????????????????a???????????-??????CPU?????????????o????


????????????????????????1?3??????????'???3????CPU????2???????????-????????????'??????????????????|??2????????-??????????2?????????oCPU??????3???????'?3????CPU??o???????????'?3???????o???????????'?a???????|?1?CPU???????????????-?????????????????????????????????????3????????o????

?3???????????a??1????????'?13???????1???????????-??????CPU????????????CPU???????????????????????????'???????????????????'??????????'??????'??????a????????????????'??'???????????????'??(?'??????????????????|??2????????-??????????2?)???

???????????????????????????-??????????????'??????o??????????????????????'????-?????????????????????-??????????????????????????????????-????????????1????1??1?????12??????????????????????o?????'??????????????????????3????????????-????????????????????3????o?????a???????????????-???????????????????|??CPU??????3??????????????????????CPU?????????????o?????3??????|??a??????????|???????????'????????????????????3??????????????????????????|????


??a???????????CPU??3????o???????????-??????CPU????3?????|??????????|????????a???oo??o??????????-?????????????????????????????????o|???-50~200?o|?????CPU???????1????(???????????-????o|????150?o|)????????-????????????????3?o????????????????????????????????????o??????????1??-18?o|?????????????2???1???????o|????????????'???????'?????????oo??a???????????????????'???'??? ??????????oo?'?????-????a??1??????????????CPU???????1??????????3????o????????????????o??????????????????-????o|??o|150?o|???????????????????????250?o|???????3??????????????????1?????????????????1?????????????????????????????????o??o????

 

3) ???????1??????????????2???????????????????2???????CPU??o??????????????o??????o????????????????????????2??a???o???o??????????????o??????o??????(?????????????)???????-??????????????????????o?????|?????????????a'1????'????'??o?


?|?????????????????????|???????????Intel?3???????CPU(????????????a???|??1???????)???????????????-?????o???????1????????????????????????????????????????2???


???????????????????????|?????|?2???????????-''(????|?3M???)????????????2?''CPU????????-??????????????????????-????????????????o?????????|?????1??????3????????-??????????????????o???|??o???????????????????-''???CPU????????-????1??'?????-?????'?????a?????|???...



Chipset 2011-10-20 09:51 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/09/28/157046.htmlChipsetChipsetWed, 28 Sep 2011 01:45:00 GMThttp://www.598club.com/Chipset/archive/2011/09/28/157046.htmlhttp://www.598club.com/Chipset/comments/157046.htmlhttp://www.598club.com/Chipset/archive/2011/09/28/157046.html#Feedback7http://www.598club.com/Chipset/comments/commentRss/157046.htmlhttp://www.598club.com/Chipset/services/trackbacks/157046.html
1????????1???|?????????????????????????????|??-???????????2??????????????????o???????????????3??????????????????o3????????????o?????????????????????
??????????o?????????????????????1????????2?????????????o?????'???1?????3??????
?|??-??????????????????????a??????????????????????
 
2????????????-|?|1??????????????????????????o??????????????'????1?????????????????????-|?|1??????'????o?????????????????'??????????1????????oo????????????
 
3??????????-|????????????????o?o?????????????????????????????????????oo?'????????a??????o?????????????????????????????????"???'?'??????????????????????????1??????????" ???????????????"?????????????????????????..."
 
4????????a?????????a????o????????????7000????????????1???????o???-|??1??????????????-?????????oo????????????????-|??????"??????2????????-?????????????????????????1??|??'??????"????o-|?????????o?????o?o?????o?????????????????oo??????????????oo????????a|????????????????????oo???????????????-|??????????????-?3a???7000 ????????o????
 
5???"???????|?????????2??-??????o????|??????????'?????????????1??????"
(?????1) ??1??????????????????-???????????????????????????????
(?????2) ??1?????|???????????????????????'?-????
(?????3) ????2??????o????a???????????????????????o??|???????1???????
(?????4) ?????????1????|????????????o?????????????????1???"??????????"?1??????????????-??????????


Chipset 2011-09-28 09:45 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/09/27/156996.htmlChipsetChipsetTue, 27 Sep 2011 11:55:00 GMThttp://www.598club.com/Chipset/archive/2011/09/27/156996.htmlhttp://www.598club.com/Chipset/comments/156996.htmlhttp://www.598club.com/Chipset/archive/2011/09/27/156996.html#Feedback5http://www.598club.com/Chipset/comments/commentRss/156996.htmlhttp://www.598club.com/Chipset/services/trackbacks/156996.html?????????

Chipset 2011-09-27 19:55 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/09/27/156961.htmlChipset). The updated technical report on the CLI, Ecma TR-84, and a new technical report on the CLI, Ecma TR-89, were also ratified.

江苏快三开奖结果In July 2005, Ecma submitted the Standards and TRs to ISO/IEC JTC 1 via the ISO Fast-Track process. The Standards were adopted in April 2006 as ISO/IEC 23270:2006 (C#), ISO/IEC 23270:2006 (CLI), ISO/IEC TR 23272:2006 (CLI, XML Libraries) and ISO ISO/IEC TR 25438:2006 (CLI, Common Generics).

江苏快三开奖结果In July 2006 the General Assembly of Ecma approved edition 4 of the Standards which correspond to the ISO 2006 versions.

Latest Standards

The following official Ecma documents are available for and the (, ). These links are direct from Ecma:

 

File name

 

Size (Bytes)

 

Content

 

 

2 614 003

 

C# Language Specification

 

 

3 219 107

 

江苏快三开奖结果Common Language Infrastructure

 

 

754 982

 

XML-based Library Specification

 

 

187 450

 

江苏快三开奖结果Information Derived from Partition IV XML File

 

 

19 329 610

 

江苏快三开奖结果XML Tool, Libraries in Microsoft© Word and PDF

 

 

589 400

 

Common Generics Library

 

 

461 074

 

Common Generics Library Reference Implementation


The official ISO/IEC documents are available from the ISO/IEC page. These links are direct from that page:

 

File name

 

Content

 

 

江苏快三开奖结果Information technology -- Programming languages -- C#

 


-

 

Information technology -- Common Language Infrastructure (CLI)
Partitions I to VI

 


江苏快三开奖结果 - Software

 

Information technology -- Common Language Infrastructure (CLI)
-- Technical Report on Information Derived from Partition IV XML File

 


-

 

Information technology -- Common Language Infrastructure (CLI)
江苏快三开奖结果 -- Technical Report: Common Generics

Current Working Draft

江苏快三开奖结果Work on the 5th edition of Ecma-335 CLI standard began in mid-2009. The TC49-TG3 task group is working on extending both the virtual machine and class libraries of the CLI specification. In addition, improvements are being made to clarify existing elements of the specification. Many of these improvements are the result of feedback received from outside the task group, for which the task group is grateful.

Posted below is a snapshot of the committee's work as of 27 March 2010.

The participants in TC49/TG3 are providing these working documents to the public for informational purposes only. The contents are subject to change as often as once a month. To participate in the standardization process, contact your organization's Ecma representative. If your company does not currently participate in Ecma and wishes to do so, please contact directly.

The following organizations and contributors are actively participating in the work of TC49/TG3:
Eiffel Software, Microsoft Corporation, Novell Corporation, Kahu Research, and Twin Roots.

Many of the organizations that are currently participating in the TC49/TG3 work have volunteered to mirror this site. The URLs for the mirror sites are:
-
- Microsoft Corporation
-
-
-

Available Documents (Documents current as of 27 March 2010)
The following working draft documents are available:

- CLI Partition I - Architecture ()
- CLI Partition II - Metadata and File Format ()
- CLI Partition III - CIL )
- CLI Partition IV - Library ()
- CLI Partition V - Binary Formats ()
- CLI Partition VI - Annexes ()
- Class Library XML ()
- Class Library Detailed Specifications ()

Annotated Standards

江苏快三开奖结果Members of the Standard committees and others have combined to produce annotated versions of the Standards. These are:

  • The Common Language Infrastructure Annotated Standard, James S. Miller & Susann Ragsdale, Addison-Wesley, 2004, ISBN 0-321-15493-2 (based on Edition 2 of Ecma-335)
  • C# Annotated Standard, Jon Jagger, Nigel Perry & Peter Sestoft, Morgan Kaufmann, 2007, ISBN 978-0-12-372511-0 (based on Edition 4 of Ecma-334)

Microsoft Implementation Specific Versions

The following documents are versions of the Standards with Microsoft implementation-specific notes added. These notes provide extra information about Microsoft's Common Language Runtime (CLR) implementation of the CLI.

 

File name

 

Size (Bytes)

 

Content

 

 

815 983

 

Common Language Infrastructure, Partition I: Concepts and Architecture

 

 

1 758 195

 

Common Language Infrastructure, Partition II: Metadata Definition and Semantics

 

 

661 414

 

Common Language Infrastructure, Partition III: CIL Instruction Set

 

 

 

 

Common Language Infrastructure, Partition IV: Profiles and Libraries

 

 

 

 

Common Language Infrastructure, Partition V: Binary Formats

 

 

 

 

Common Language Infrastructure, Partition VI: Annexes

The Ecma 4th and ISO 2nd Editions

Aside from bug fixes, major enhancements from previous editions include:

CLI

  • First-class support for generics at the runtime and class library level
  • An API to help developers begin multithreaded and parallel programming
  • Enhancements to the Common Intermediate Language (CIL) and Common Language Specification (CLS)
  • An interchangeable debug format

C#

  • First-class language support for generics
  • Anonymous methods
  • Iterators
  • Nullable Types

Previous Editions Background

In August, 2000, Microsoft Corporation, Hewlett-Packard and Intel Corporation co-sponsored the submission of specifications for the Common Language Infrastructure (CLI) and C# programming language to the international standardization organization Ecma. As a result, Ecma formed two task groups (TG3 and TG2, respectively) within TC39, its technical committee responsible for programming languages and application development.

During the next year, the co-sponsor companies, in conjunction with other Ecma members and guests (including IBM, Fujitsu Software, Plum Hall, Monash University and ISE), refined these specifications into standards. In December, 2001, the Ecma General Assembly ratified the 1st edition of the C# and CLI standards as Ecma-334 and Ecma-335, respectively. A technical report on the CLI, Ecma TR-84, was also ratified.

In late December, 2001, Ecma submitted the standards and TR to ISO/IEC JTC 1 via the latter's Fast-Track process. The subsequent 6-month evaluation and comment period resulted in two NO votes (Japan and UK) on the draft standards, and one NO vote (Japan) on the draft TR. All comments resulting from this review were considered at a ballot resolution meeting held in October, 2002. The two NO votes on the standards were resolved, making acceptance unanimous. However, Japan did not change its NO vote on the draft TR (Japan would like to see a formatted/readable rendering of the CLI class library as part of the standard, not as a TR; this will be considered for a future edition).

The ISO/IEC standards and TR were published in April, 2003, and are known formally as ISO/IEC 23270 (C#), ISO/IEC 23271 (CLI) and ISO/IEC 23272 (CLI TR). Equivalent specifications were adopted as 2nd江苏快三开奖结果 edition standards and TR by Ecma at its December, 2002, General Assembly.

Joining Ecma

To participate in the standardization process, contact your organization’s Ecma representative. If your company does not currently participate in Ecma and wishes to do so, please directly.

Acknowledgements

The following organizations have participated in the work of Ecma TC39/TG2 and TC39/TG3 and their contributions are gratefully acknowledged: Borland, Fujitsu, Hewlett-Packard, Intel Corporation, International Business Machines, ISE, IT University Copenhagen, JSL (UK), Kahu Research (New Zealand), Microsoft Corporation, Monash University, Netscape, Novell Corporation, OpenWave, Plum Hall, Sun Microsystems.

Many of the organizations that have participated in the TC39/TG2 and TC39/TG3 work have volunteered to mirror this site. The links for the mirror sites are:

  • Intel Corporation
  • Microsoft Corporation




Chipset 2011-09-27 14:43 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/09/09/155461.htmlChipsetChipsetFri, 09 Sep 2011 08:39:00 GMThttp://www.598club.com/Chipset/archive/2011/09/09/155461.htmlhttp://www.598club.com/Chipset/comments/155461.htmlhttp://www.598club.com/Chipset/archive/2011/09/09/155461.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/155461.htmlhttp://www.598club.com/Chipset/services/trackbacks/155461.html
1??? ????oo??????????????????????????????o???????????'??????????????????o??????????????????????????????????????????a???????????????12????1????????-??'???????????????????o? ???

2??????????????????????????????????????????????????????????-?oo????o??????a????1??????????????????????????????????o??????????????????'????????????|???????'?3?????|?????o????

3???????oo???????????????????????1?????“?????????????o2???”???3?????????????a??a?'????????????-????????????????????????-?oo????????“?????????????****?????a????|????

4?????'?-???????????a???????o????????????????????3????????????????????????????????a??????-?o?????????'?-???-????'???“?????????‘IP’(?????)????????????”

5?????????????????1???????????????????????????1?????'????????????o?????????'?????????????????????????1????????????????????????????'??????????o???????????????????|????????????

6?????????????????o?????????????????a?-???????????|??????1'?oo??1?????a????o???3?-??'???“????????????????'??????????????”??3?-??????????????“??o????1????”“????|??-???????a?o??2????????a????????o?????????1 ?|??????????????????'???????1??????????o??????......”?2??-?????'??????????|??-??2????-????o??????o??????????????|?????o????

7?????????????|?????? ???????1??????????o?a??????? ??????|??????????|??3?????????????????????????????????????-|??|??? ????????????? ??????????a?? ?????????????????????????????

9?????3?????????????3?????????2???????????1???????a??????????????o????????????????|?????????o???????????3???????2???o??????????????o??3???????????????????o??o????--????1??????????o?????????3??????

10???????-???????|?????|??|???????

???????|??'??????????o????o??a3?|??1?????|??????????

??????????-??????????

    ?|??'?????????a3?|??????????

??????????'???????1??????????

????????????????????????'??????-??-???????????o????

11??????oo???????-??????????????-?????????|?-??????????????????????2??????????-?????????????-??????????????????????a?????????-???????????????3????????????????|??????????????????????|?????o????

12?????????-|??????????????????????????????????????????????????????'??????????????-|????????????????1???????????????????????????????????????'?????'??????????????1??????-????????????

13??????oo????????1?????????????????????????-???????????????????2?????????o?????????3?????-????????????????????o???????????????????????????????????1??????????|????????????o???????????????????????????

14???'?????????1??????????????????????????????????????????????????????????????????'???????????????3????****????????????????????????oo????????????????***????2??3????o????

15?????????????????????1??-?????????????????????????????????????o?????1?????????????????????-??'???“????????-????2??a?????????????????????a?????????????????????????????2?????????????????a.........


Chipset 2011-09-09 16:39 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/09/07/155267.htmlChipsetChipsetWed, 07 Sep 2011 03:12:00 GMThttp://www.598club.com/Chipset/archive/2011/09/07/155267.htmlhttp://www.598club.com/Chipset/comments/155267.htmlhttp://www.598club.com/Chipset/archive/2011/09/07/155267.html#Feedback3http://www.598club.com/Chipset/comments/commentRss/155267.htmlhttp://www.598club.com/Chipset/services/trackbacks/155267.html

??''????2????????????o????????-????


江苏快三开奖结果1?????????????????-????????????????-???????-?????????????????????o2?????a??????????-???????-??-???????????o2?'????-??-?????????????????????????????——????o2??????????????a?

??????

2??????-???o????????????????????3???????o2????????????????????'???????????????23?2???????o?????????-??-???????????? ???????????????1????2?????-??-????????????????????????o2?????????????a?'????????'???a?'?????????????????-???????????????a???????????1??????o2?????????????o2???????????o2??? ??????????o2??????-?-??????1??????-????????????????o2?'????-??-??????????????????????????????——????o2??????????o???a?

??????

江苏快三开奖结果3???????????-?o??????o?o???'?????-?????????????-|'1??????????o??????????o2??????????????o??????'???????????????????????? ?3??o??????1???????????1?????????????a???????????-???????????????????????o2??o????o??-????21???????3??????'?????????-??'???????o2???????o????????????????|??????-??????????o2??????????'????-??-???? ??????????????????????——????o2??????????????a?

??????

4??????????1'???????o2??o?????????????????1??????o????????????????-????????????????????????????????'?????o????? ????o2??????????????????????????a?????????????????????????????o????????o2????????????????????????'????3??????????????????-??-?????o???????o|???????????'????????????????o2?12???????'??????????'????? ?????????-????????-???????'??????????????????o2??????????o2?'????-??-???????????????????????'???——????o2???????????a?

??????

5???????o2??????1???????????o2????????1?????????????????a???????o?????????1?????????????????1?|??????????????a?-? ?-?????????????????1|???????-???????|?????a?????????????????o????????????????????????????????????o????o??????2???????????a???????????????????????????'??????o???2????????????-?????????????oo?? ????????-????????????|????3????1?-?????????????????????????????????o2????????????????|?o??a?????????????o2???1'?????'???o??|?????????????????????????oo?????????????o2?1???-????????????????o2 ?'??????????????——???????o???a?

??????

6??????-??????1??????????-|???????????????????????????o??2????????o2??????????'??????o????o???a???????'???????'????o????????????????-??-???????????????????????????????''????o2???????o2?????3???|?????1???????o??????????????o2?'?????????????——????????-??a?

??????

江苏快三开奖结果7??????-????????????????1'???????????????o?????????????????????-|????????????????????????????????????????????????o????????????????????????????????????????o????o???????????????-???3???????o2???????o??o?????|???'?????oo???????o????????o2?'??????????1???????——???????????a?

??????

江苏快三开奖结果8???????1'???????o2????o???????????????o?????????????????'?????2???????-??1?????o???????????????????????????o2?2????????????????o????????o2???o???????????????-??????????-?????'???????????o2??????-???2?????2?????????????3a??????????o2??'?'????-??-?????????-???????????????——?????????????????a?



Chipset 2011-09-07 11:12 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/23/154123.htmlChipsetChipsetTue, 23 Aug 2011 06:07:00 GMThttp://www.598club.com/Chipset/archive/2011/08/23/154123.htmlhttp://www.598club.com/Chipset/comments/154123.htmlhttp://www.598club.com/Chipset/archive/2011/08/23/154123.html#Feedback6http://www.598club.com/Chipset/comments/commentRss/154123.htmlhttp://www.598club.com/Chipset/services/trackbacks/154123.html??????????a?-???|?a???????-???|?a???o??o????1'?????????????|?19880521??o1988?1'5???21??????????-????a???????????|????3???????????????1????????????????????????????????????'???o???|????????o?????a?-???|?a???-???????a???????????-??????3???????????-?????????????????????????-???????????|?19861330????????????????????o??????13?????????????|?19870230???2??????????o??????30???????????????????a??|???????????????a????????????????????-???|?a???????????o?????????o???????'??1900?1'1???1????32099?1'12???31????1??'???????????????a??o?'????o????????a????o???????3?????????????

??o????????????????????-????????????????????-???|?a????o|?????|????3?????????????????????|????????-?????????????????1'????????|????3??????????????????????????????????|????3???????????1?????????????????1????????????a??????????????1??????o???????????-???|?a??????????????????|??????o|???????????????|??????????1??2??????????-???|?a?????????C???o??o????????|???????????????????????????-|?1????????????

????????C??????(?????C++)????o??????????????????o??o????????????

#include <string.h>   // strlen, strncpy
#include <ctype.h>   // isdigit
#include <stdlib.h>   // atoi

int isValidDate(const char* str)
{
    // ?????????o|
    const int LEN = 8;
    int len = strlen(str);
    if(LEN != len)
        return 0;

    // ?????????????-???|?????|?????o???-?
    int idx = 0;
    while(idx < LEN && isdigit(str[idx])) ++idx;
    if(idx < LEN)
        return 0;

    // ???????1'????????|??[1900, 2099]
  char year_str[5] = { 0 };
  strncpy(year_str, str, 4);
  int year = atoi(year_str);   // to extract year
  if(year < 1900 || 2099 < year)
        return 0;

  // ??????????????????????????|????1?????
    char month_str[3] = { 0 }, day_str[3] = { 0 };
    strncpy(month_str, str + 4, 2);  // ?????????????-???|?a?
    strncpy(day_str, str + 6, 2);      // ?????????????-???|?a?
    int day = atoi(day_str);
    int month = atoi(month_str);
    switch(month)
    {
      case 1: case 3: case 5: case 7: case 8: case 10: case 12: /* 31?? */
          return 0 < day && day < 32;
        case 4: case 6: case 9: case 11:                          /* 30?? */
          return 0 < day && day < 31;
        case 2:                  /* 2?????????????1????????1': 29??????13?1': 28?? */
        {
          int leap = (0 == year % 4 && 0 != year % 100) || (0 == year % 400);
          return (1 == leap && (0 < day && day < 30)) || (0 == leap && (0 < day && day < 29));
        }
        default: return 0;
    }
}

/* ??????????o????????????????? */

#include <stdio.h>  // printf

int main ()
{
    const char* str1 = "20552029";
    const char* str2 = "18960321";
    const char* str3 = "2000a220";
    const char* str4 = "20110132";
    const char* str5 = "19990138";
    const char* str6 = "209905-9";
    const char* str7 = "20000229";
    printf(isValidDate(str1) ? "valid\n" : "invalid\n");
    printf(isValidDate(str2) ? "valid\n" : "invalid\n");
    printf(isValidDate(str3) ? "valid\n" : "invalid\n");
    printf(isValidDate(str4) ? "valid\n" : "invalid\n");
    printf(isValidDate(str5) ? "valid\n" : "invalid\n");
    printf(isValidDate(str6) ? "valid\n" : "invalid\n");
    printf(isValidDate(str7) ? "valid\n" : "invalid\n");
}

Chipset 2011-08-23 14:07 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/23/154114.htmlChipsetChipsetTue, 23 Aug 2011 04:41:00 GMThttp://www.598club.com/Chipset/archive/2011/08/23/154114.htmlhttp://www.598club.com/Chipset/comments/154114.htmlhttp://www.598club.com/Chipset/archive/2011/08/23/154114.html#Feedback2http://www.598club.com/Chipset/comments/commentRss/154114.htmlhttp://www.598club.com/Chipset/services/trackbacks/154114.html

??????????????????????????|????????????????a??'??????o??????????????a1???0????a??a???(??????)???????|??????????????100????o?????????1100100??????1???????????????a1???????? ??o2?????????(bsf, bit scan forward)???6?????????(bsr, bit scan in reverse order)??????o???a???o??-????????a??????????3?o???bsf?????bsr?????????????

???3????a???????????????a??3?3????????????????????????3???????????1??????CPU?????????????????????????????????????????????????????CPU?????????????????????????????????????????o|?1????????????
?????????????a64????????|????'???o?????????????????a1?????bsf, AT& T?????(gcc?????)????????????????

 1 // bit scan forward for 64 bit integral number
 2 /* ============================================ */
 3 inline int bsf_asm (uint64_t w)
 4 {
 5   int x1, x2;
 6   asm ("bsf %0,%0\n" "jnz 1f\n" "bsf %1,%0\n" "jz 1f\n" "addl $32,%0\n"
 7      "1:": "=&q" (x1), "=&q" (x2):"1" ((int) (w >> 32)),
 8      "0" ((int) w));
 9   return x1;
10 }


?|??????C????????????????????????1o???|?o???????-????2???????????-|????????????????????o?????????

 1 // bit scan forward for 64 bit integral number
 2 /* ============================================ */
 3 inline int bsf_folded (uint64_t bb)
 4 {
 5      static const int lsb_64_table[64] =
 6    {
 7       63, 30,  3, 32, 59, 14, 11, 33,
 8       60, 24, 50,  9, 55, 19, 21, 34,
 9       61, 29,  2, 53, 51, 23, 41, 18,
10       56, 28,  1, 43, 46, 27,  0, 35,
11       62, 31, 58,  4,  5, 49, 54,  6,
12       15, 52, 12, 40,  7, 42, 45, 16,
13       25, 57, 48, 13, 10, 39,  8, 44,
14       20, 47, 38, 22, 17, 37, 36, 26
15    };
16    unsigned int folded;
17    bb ^= bb - 1;
18    folded = (int) bb ^ (bb >> 32);
19    return lsb_64_table[folded * 0x78291ACF >> 26];
20 }


?|??????3????????????????'??????a??'??????o??????????????a1???????????????????????????????????

 1 // bit scan in reverse order for 64 bit integral number
 2 /* ============================================ */
 3 inline int bsr_asm (uint64_t w)
 4 {
 5   int x1, x2;
 6   asm ("bsr %1,%0\n" "jnz 1f\n" "bsr %0,%0\n" "subl $32,%0\n"
 7      "1: addl $32,%0\n": "=&q" (x1), "=&q" (x2):"1" ((int) (w >> 32)),
 8      "0" ((int) w));
 9   return x1;
10 }


?|??????C?????????????????1?????????????????divide and conquer ?????????????????a??????

 1 // a logn (n == 32)algorithm for bit scan in reverse order
 2 /* ============================================ */
 3 inline int bsr32(uint32_t bb)
 4 {
 5      static const char msb_256_table[256] =
 6    {
 7       0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
 8       4, 4, 4, 4, 4, 4, 4, 4,4, 4, 4, 4,4, 4, 4, 4,
 9       5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
10       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
11       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
12       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
13       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
14       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
15       7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
16    };
17    int result = 0;
18 
19    if (bb > 0xFFFF)
20      {
21       bb >>= 16;
22       result += 16;
23    }
24    if (bb > 0xFF)
25      {
26       bb >>= 8;
27       result += 8;
28    }
29 
30    return (result + msb_256_table[bb]);
31 }
32 
33 /* ============================================ */
34 inline int bsr_in_C(uint64_t bb)
35 {
36   const uint32_t hb = bb >> 32;
37   return hb ? 32 + bsr32((uint32_t)hb) : bsr32((uint32_t)bb);
38 
39 }
40 


?????????a????1??1???????????'?????????-1023????3?o????o|???????|?????????????????????o????

 1 // bit scan in reverse order for 64 bit integral number
 2 /* ============================================ */
 3 inline int bsr_double (uint64_t bb)
 4 {
 5    union
 6    {
 7       double d;
 8       struct
 9       {
10          unsigned int mantissal : 32;
11          unsigned int mantissah : 20;
12          unsigned int exponent : 11;
13          unsigned int sign : 1;
14       };
15    } ud;
16    ud.d = (double)(bb & ~(bb >> 32));
17    return ud.exponent - 1023;
18 }
19 


??????uint64_t???uint32_t?????C++???????????????????????'???????????????????o??????unsigned long long???unsigned long??????????????????????????????????????????????????a??????????????????????????????????o???????''??????????????????o?????????????|????????2?????????????o??????GNU???


Chipset 2011-08-23 12:41 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/19/153849.htmlChipsetChipsetFri, 19 Aug 2011 06:47:00 GMThttp://www.598club.com/Chipset/archive/2011/08/19/153849.htmlhttp://www.598club.com/Chipset/comments/153849.htmlhttp://www.598club.com/Chipset/archive/2011/08/19/153849.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/153849.htmlhttp://www.598club.com/Chipset/services/trackbacks/153849.html

2007?1'????????????????????????????????1|????????????????????????????????a?o???-????????o??????o???????????'?????????o???'2'???????????????????o??????????????'??????????????????????????????????????'??|???????????????????????????|??oo??????????a????3?-???????o??o???-??????????????????3?-????????????????a?????????????2??'???????????

 ??????o???-???????????????????????????|????o????????????????“?????????????????o?o????????????”???

“?????????1??????????????2????????????????????1|???????????a??1?????????”???|??oo?????????????3?-?????'???

 “??????-??????o???????oo???????2????????????oo?????????????”?????????'???

“??o????1??????????????????????????????'????????????????????o????????????????????????????????????????”???|??oo??????????????????“???????????2?????????????????????o?????|???o???'2????-??-????????????????'????????1?????3??o???o???????????-??-??????1?o??????3???????a??????????????????????????o?????????????????????????????????????????1???????????”

“???????????????|???????????o???????????'????o??????????????????????|?????oo????????????????o???'2????-??-???????????????????'????????|??????????????????????????????????3????o?????????????????????????”????????????'???

“???????????????????????????????????????1??????”?????'?2?????'?????????3?-????????????????1??????????????????????o????“????????????????????oo??????????????????????????o?????????????2???????1??????????????????????????????????|????????????????????????????????????????a??|??????????”????3?-??2???'?????????????-?????????????????????????

?????????????????????????????????????-?????????????????a?????????????a????????oo?'???“??????o?????-??-????????'?????1??????????????????????????????????????????????????????????????????oo????????????????”?'?????????????????'??????????|?????????????????2??o??????????o?o???????2???o??o??????????????????'o?????????????o??????????????????????????“???????????|??1???????????”

????????????????????????????????????????????'????o???a?????“?????????????o?????2???|·?'?2??1?????????”

????????????????'???????????????????????????????????????????o300?????????????'?2??1????1????????????o800?????????????????·???????????????????????o30????????25????????????2???????1??????o???????????-?????????????????????'????????????-?1????????o?????????????“????????????????????????????”????o?????????????????a?????o?o???????????????o??????????????o?????????????????'???????????????????????????????????????????oo?o?o??o|???o???'2???o?'???????-??-?????????



Chipset 2011-08-19 14:47 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/19/153838.htmlChipset

1

2

3

4

5

6

7

8

9

10

11

class Singleton {

    Singleton();

    ~Singleton();

  public:

    static Singleton& instance();

};

 

Singleton& Singleton::instance() {

    static Singleton singleton;

    return singleton;

}

This implementation of a Singleton leaves the issue of thread safety unresolved. If multiple threads enter the instance routine simultaneously and if this routine has never been executed before, various problems may occur, depending on the compiler and platform. For example, the constructor of my Singleton may be executed multiple times or not at all. Alternatively, the constructor may be executed exactly once, which is correct, but one of the instance江苏快三开奖结果 routines may return before the construction is completed—again, leading to unpredictable and hard-to-debug failures. As you'd expect, you can eliminate this race condition by using one of a number of various synchronization mechanisms. Listing Two, for example, employs a mutex. In Listing Two, I did not show how the mutex variable is initialized. The mutex itself is a Singleton! If this mutex has a nontrivial constructor or destructor, we have a chicken-and-egg problem.

江苏快三开奖结果Listing Two

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

class Singleton {

    Singleton();

    ~Singleton();

    static Singleton *s_singleton;

    static void init();

  public:

    static Singleton& instance();

};

Singleton *Singleton::s_singleton = 0;

void Singleton::init() {

    static Singleton singleton;

    s_singleton = &singleton;

}

Singleton& Singleton::instance() {

    lock(&mutex);

    if (!s_singleton) {

        init();

    }

    unlock(&mutex);

    return *s_singleton;

}

UNIX: pthread Solutions

Solving the problem of initializing the mutex on UNIX platforms isn't difficult. The pthread library available on these platforms provides a mutex that is a Plain Old Data (POD) type requiring only static (nonruntime) initialization, as in Listing Three. Additionally, the pthread library provides a mechanism called "once江苏快三开奖结果 routines" that can also be used to solve this initialization problem (Listing Four).

1

2

3

4

5

6

7

8

9

Singleton& Singleton::instance() {

    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

    pthread_mutex_lock(&mutex);

    if (!s_singleton) {

        init();

    }

    pthread_mutex_unlock(&mutex);

    return *s_singleton;

}

Listing Three

1

2

3

4

5

Singleton& Singleton::instance() {

    static pthread_once_t once_control = PTHREAD_ONCE_INIT;

    pthread_once(&once_control, &Singleton::init);

    return *s_singleton;

}

Listing Four

Windows: Spin-Lock Solution

Unfortunately, the Singleton I was implementing had to support Windows. That's where the main complication arose. Even critical sections, which are the simplest synchronization mechanism available on Windows applicable for my Singleton, do not support static initialization; a call to InitializeCriticalSection is required. As for once routines, there is no support for them in the Win32 API.

Of course, I could have implemented a simple spin-lock using the Interlocked family of routines and the Sleep function, as in Listing Five.

1

2

3

4

5

6

7

8

9

10

11

Singleton& Singleton::instance() {

    static volatile LONG lock = 0;

    while (InterlockedExchange(&lock, 1) != 0) {

        Sleep(1);

    }

    if (!s_singleton) {

        init();

    }

    InterlockedExchange(&lock, 0);

    return *s_singleton;

}

Listing Five

Listing Five can be further optimized in two important ways. First, you can replace the lock variable with a three-state control variable (Listing Six).

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

Singleton& Singleton::instance() {

    static volatile LONG control = 0;

    while (1) {

        LONG prev = InterlockedCompareExchange(&control, 1, 0);

        if (2 == prev) {

            // The singleton has been initialized.

            return *s_singleton;

        }

        elsif (0 == prev) {

            // got the lock

            break;

        }

        else {

            // Another thread is initializing the singleton:

            // must wait.

            assert(1 == prev);

            Sleep(1); // sleep 1 millisecond

        }

    }

    if (!s_singleton) {

        init();

    }

    InterlockedExchange(&control, 2);

    return *s_singleton;

}

Listing Six

  • No threads have yet attempted to initialize the Singleton. (This is the initial state.)
  • The Singleton is in the process of being initialized. (Any thread, except the first thread that sets the control variable to this value, must wait for the initialization to be completed.)
  • The initialization has been completed.

Introducing these three states ensures that, once the initialization is completed, no spinning is necessary, even if multiple threads enter the Singleton::instance routine simultaneously.

The second optimization lets the sleep interval adjust dynamically using exponential backoff (Listing Seven; available electronically; see "Resource Center," page 5). If the initialization of the Singleton (the constructor of our Singleton江苏快三开奖结果 class) takes a relatively long time or if there are many spinning threads, choosing small sleep intervals may create considerable overhead. Moreover, this problem is exacerbated whenever spinning threads delay the progress of the thread performing the initialization. On systems with less sophisticated thread scheduling (Windows 98, for instance), this deficiency may even bring the entire system to a halt.

江苏快三开奖结果On the other hand, if the initialization of the Singleton is relatively quick, choosing a large sleep interval causes an unnecessary delay. Although adjusting the sleep interval dynamically does not solve these problems completely, it does reduce their likelihood.

With these substantial optimizations, the spin-lock approach, though inelegant, is acceptable for many applications. Nonetheless, because I was looking for a generic solution that I planned to implement in a low-level library used by a wide range of applications and for a variety of Singleton objects, the spin-lock approach did not appeal to me.

Windows: Named-Mutex Solution

In search of a better solution, I decided to look at how two open-source libraries—Boost.Threads (boost.org/doc/html/threads.html) and Pthreads-w32 (sourceware.org/pthreads-win32/)—deal with this problem. Although neither library is directly concerned with Singletons, each has code that implements once-routine support on Windows. Boost.Threads provides a portable set of handy MT-related primitives to C++ programmers. Naturally, the platforms supported by this library include Windows. Pthreads-w32, on the other hand, implements a pthread-compatible layer, including pthread_once, on top of the Windows API, thus simplifying the porting of MT programs from UNIX to Windows. I reasoned that whatever technique these libraries use to implement once routines on Windows, it should be possible to use that same technique to implement my Singleton.

The technique I discovered in Boost.Threads (libs/thread/src/once.cpp under the Boost source tree) relied on a special Windows feature that lets a name be associated with a mutex. If a thread (not necessarily within the same process) creates a mutex with a name that already exists, instead of creating a new mutex, the system returns a handle to the existing one. The system also makes sure that the mutex is not destroyed as long as there are any open handles to it. Finally, the system guarantees that creating a mutex and closing a mutex handle are atomic operations. Listing Eight (available electronically) shows how a named mutex can be used to implement our Singleton.

The name of the mutex is designed to be unique. If you don't think the string "Singleton::instance" provides sufficient guarantee from collisions, you can use a random string generated by your favorite method (the string actually used in the Boost code is "2AC1A572DB6944B0A65C38C4140AF2F4"). Also, note that this code uses the Double-Checked-Lock optimization (www.cs.wustl.edu/~schmidt/PDF/DC-Locking.pdf). To avoid the various problems with naïve implementations of this optimization (www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf), we make sure that all access to the flag is done through Windows interlocked routines, which incorporate all the necessary memory barriers. The InterlockedExchangeAdd(&flag, 0) call—a no-op incrementing the flag by 0—is just a way of using interlocked routines for reading the flag. (The same effect can be achieved more efficiently with some inlined assembler.)

Although a clever technique from the Boost.Threads library lets you improve upon the previous implementation by removing the inherent unpredictability of spinning, the solution suffers from several inefficiencies. To begin with, named mutexes are intended to be used for synchronization across process boundaries rather than among threads within the same process. Manipulating, and creating such "interprocess" mutexes is expensive—substantially more so than those used to synchronize threads. Moreover, with this heavy approach, a named mutex has to be created at least once, even when there is absolutely no contention—even if the application using this Singleton is singlethreaded! Finally, generating a unique mutex name from a pointer is artificial and rather inelegant. Given these drawbacks, this solution, although acceptable in many applications, did not satisfy the needs of my high-performance reusable infrastructure library.

Developing Class QLock

Next, I looked at the Pthread-w32 library. The code I discovered in that library's implementation of pthread_once (pthread_once.c, CVS version 1.16) used an approach radically different from either of the two techniques just discussed: If multiple threads enter pthread_once simultaneously, the first thread that has to wait (the second thread overall) creates a synchronization object (a Windows event object, in this case). The last thread to leave the routine destroys the object. An atomic reference count keeps track of the number of threads involved. All of the problems of the previous two approaches seemed to be avoided. Unfortunately, a closer examination of the code uncovered a race condition. After a few attempts at fixing the problem (see pthread-w32 mailing list archive if you are interested in the details; sources.redhat.com/ml/pthreads-win32/), it became clear that this general approach is fundamentally flawed and cannot be fixed.

Although reference counting used by the pthread_once implementation did not work, trying to fix it gave me some ideas. What if each thread that had to be suspended (waiting for another thread to complete the initialization of a Singleton), created and then destroyed its own synchronization object? For instance, I knew how the MCS implementation of spin-locks, to reduce contention, makes each thread wait spinning on its own flag. Could I use a similar technique, but instead of spinning, make each thread wait on its own semaphore or event object? It turned out that it was not only possible to make such a technique work, but the resulting code was fairly simple, too. Listing Nine (available electronically) uses this specialized waiting technique to implement my Singleton.

The central idea of this new approach is encapsulated in class QLock. Each instance of this class represents a lock held on the mutex that was passed as a constructor argument. A mutex itself, which is represented by the QLock::Mutex type, is just a pointer, which is set to zero when the mutex is not locked. When the mutex is locked, it points to the tail of the queue of threads waiting on this mutex. Each thread in the queue is represented by the instance of class QLock that the thread created to obtain the lock. In other words, the mutex is a pointer to the QLock instance created by the last thread waiting in the queue. This QLock instance is linked to another QLock instance, which was created by the previous thread in the queue, and so on. The QLock instance at the head of the queue corresponds to the thread that currently holds the lock.

A Closer Look at QLock

Table 1 lists the QLock class data members, while Table 2 lists the values that d_readyFlag and d_nextFlag may have. The constructor QLock::QLock atomically exchanges the mutex pointer for this. If the mutex pointer was 0 prior to the exchange, the lock is obtained and the constructor completes. If the mutex pointer was not zero, this instance of QLock has to join the queue and wait for the ready flag.

 

Data Member

Description

d_mutex

江苏快三开奖结果Pointer to the mutex locked by this QLock instance.

d_next

江苏快三开奖结果Pointer to the next instance of QLock in queue waiting to obtain the lock.

江苏快三开奖结果d_readyFlag

江苏快三开奖结果Flag used to indicate that the lock has been released by the predecessor.

d_nextFlag

江苏快三开奖结果Flag used to indicate that the next pointer (d_next) has been set by a successor.

江苏快三开奖结果Table 1: QLock class data members.

 

Value

Description

0

Initial value indicating that the flag is not set.

-1

Indicates that the flag was set before an event object had been installed into the flag.

Neither 0 nor -1

Indicates that an event object has been installed into the flag, which now holds the handle of the event object.

Table 2: Values that d_readyFlag and d_nextFlag may have.

The destructor QLock::~QLock, using one atomic compare-and-exchange operation, checks if the mutex pointer contains the value of this pointer. If it does, it resets the mutex pointer to zero, thus releasing the mutex. If the mutex no longer contains the value of this pointer, the queue has been formed, and the destructor must pass the lock to the next instance in the queue. The destructor first waits on the d_nextFlag to make sure that the next pointer has been set, then sets the d_readyFlag.

The algorithms used in QLock's constructor/destructor are basically the same as those used to lock/unlock MCS spin-locks. The setFlag and waitOnFlag methods are where we make our important deviation from MCS locks. Instead of spinning (as is appropriate for a spin-lock), the waitOnFlag routine:

  1. Creates an event object.
  2. Atomically checks that the flag has not yet been set and installs the event object's handle into the flag.
  3. Proceeds to wait on the event object.

Now compare our QLock-based solution for the Singleton problem with the two previous solutions (spin-lock-based and named-mutex-based). Similar to the named-mutex-based solution, you avoid the unpredictable behavior of the spin-lock: Instead of spinning, waiting threads are suspended by the kernel, and resumed as soon as the mutex is available. Additionally, you avoid the problems with the named mutex: Event objects used for synchronization are process local, do not require artificial names, and are created only when threads need to be suspended due to contention. When there is no contention (when only one thread enters the Singleton::instance method at the time of initialization), no synchronization objects are created: The overhead is simply that of a few atomic operations.

Observations

After using the synchronization mechanisms implemented by the QLock class to solve the Singleton problem on Windows (and more generally, the problem with the static initialization of mutexes on Windows), I discovered that QLock has some other important properties that made it attractive for other applications (including on UNIX). QLock::Mutex has a small memory footprint (one pointer), and a small initialization cost (that of initializing a pointer with 0). Additionally, when there is no contention, QLock is fast. If no wait is necessary, locking a QLock requires just one atomic instruction and no system calls. If there are no waiting threads, unlocking is also just one atomic instruction.

江苏快三开奖结果Furthermore, when there is contention, the cost of constructing event objects (or semaphores on UNIX) can be virtually eliminated by using a lock-free pool of allocated event objects. This pool works particularly well because the number of event objects required never exceeds the number of waiting threads—an inherently small number.

One common scenario in which QLock appears to be of great use is when you have a large collection of some kind of items that are accessed from multiple threads. To increase concurrency, it may be logically possible and desirable to maintain a mutex per item of the collection (instead of maintaining a single mutex for the entire collection). It is often the case, though, that the memory footprint and the initialization cost of a standard mutex or critical section would be prohibitive due to the (sometimes very large) size of the collection. QLock, because of its small size and negligible initialization cost, may be able to provide a viable solution to fine-grain locking.




Chipset 2011-08-19 10:28 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/16/153564.htmlChipsetChipsetTue, 16 Aug 2011 07:05:00 GMThttp://www.598club.com/Chipset/archive/2011/08/16/153564.htmlhttp://www.598club.com/Chipset/comments/153564.htmlhttp://www.598club.com/Chipset/archive/2011/08/16/153564.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/153564.htmlhttp://www.598club.com/Chipset/services/trackbacks/153564.html??3?o?B+???????????????????????????????????|??????C++???????????
http://idlebox.net/2007/stx-btree/
????????????????????????????

Chipset 2011-08-16 15:05 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/16/153559.htmlChipsetChipsetTue, 16 Aug 2011 06:14:00 GMThttp://www.598club.com/Chipset/archive/2011/08/16/153559.htmlhttp://www.598club.com/Chipset/comments/153559.htmlhttp://www.598club.com/Chipset/archive/2011/08/16/153559.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/153559.htmlhttp://www.598club.com/Chipset/services/trackbacks/153559.html?????????

Chipset 2011-08-16 14:14 ???????o
]]>
C++博客-Welcome to Chipset's homepage! http://www.598club.com/Chipset/archive/2011/08/16/153557.htmlChipsetChipsetTue, 16 Aug 2011 06:08:00 GMThttp://www.598club.com/Chipset/archive/2011/08/16/153557.htmlhttp://www.598club.com/Chipset/comments/153557.htmlhttp://www.598club.com/Chipset/archive/2011/08/16/153557.html#Feedback0http://www.598club.com/Chipset/comments/commentRss/153557.htmlhttp://www.598club.com/Chipset/services/trackbacks/153557.html

?o??????????????o?

??'?????????????o????????????????'?????????????????a????????????????????????????????????2???????|????????????????o?-?????|?????????????????????????????????????a????'??????????-??o?????2???????o?????|??????????o????????????????????????????????????????13???????'????o|?????1?o??????a???????o????????o?o?????????????o??????????????o?????????'?????????????o???????????????????????'?????????????????????????????????????????????13?????????????????o??????????????o?????13???????'??????o|??oO(n2)?????????????????????????'??????o|??o(n2)?????????????o??o?????2???????o???????????o?????'??????o|??oO(nlogn)?????o?'??????o|??oO(1)????o??????????????o??????|?3?????????o??????????????

??????????a?o?????2???????o?????-???????????|????????a?o?????????????????a??????????????1????????|?????????????????????????????

|??????o?????????-?'???????a????'??????????|????????????-?'???????a????'??????????????????????????????|?1?????|?????????????3?1?????????????????-?'????????o?????2??1????|???????|?1?????????????????-?'????????????????'??-??o????????????1????|????????3?1?????3?1????????????'?????????????'??-??o??????????1?????????????????????????-??????????????a??-?'??????????1?????-?????????????'?????????????????????????????o?-????

???????????????????????????????????|?????o??????-????????a????'??????????????????????????'????????-???????1??????????????o?????????????'??????????????????????????????????????o??????????????o??3???????????????????o??????????????o?????3???????|?????o??????-???????a????'??????????????????????????'????????-??????????????????????a???????????????????????a????????????o??????????????o??3?????????????????????????3?????????????“?????”?????????“?????”????????????????o??????????????????

??????????1??????o??????????????o??????????????????1?????1????????o??????????????o???????????o????2????????1?????????|???????????????????????o|???????????????|????????-??????????????3????????o?????????????????1?????????????????????o???????o|?a?????????????????o3???

??????o??????????????o???1?????a????o??o????????o??????o?????????????????????o?a??????????????????a??????o????????o?????????'??????????o?????3??????????????????????a?o?????????-????????'?????????????o????o????????????o??????????????o?|?????????1?????????????o??o???????????????????????o?????3?(????????????????????????o?)???????o??????????????o????????????


 1 template <typename RandomIter, typename T, typename Compare>
 2 inline void linear_binary_insertion(RandomIter first, RandomIter
 3                                     last, T value, Compare cmp)
 4 {
 5   RandomIter curr = upper_bound(first, last, value, cmp);  // ?????????????????????1?????o???????
 6   copy_backward(curr, last, last + 1);                               // ????????|??????????o??????????1???????????????????????
 7   *curr = value;
 8 }
 9 
10 template <typename RandomIter, typename Compare>
11 void binary_insertion_sort(RandomIter first, RandomIter last, Compare cmp)
12 {
13   if(last - first < 2)
14     return;
15   for(RandomIter it = first + 1; it != last; ++it)
16     linear_binary_insertion(first, it, *it, cmp);
17 }


Chipset 2011-08-16 14:08 ???????o
]]>