Skip to content

Commit f4eb373

Browse files
authored
Merge branch 'master' into mb-hashmap
2 parents 1fc3bc0 + 2cd0768 commit f4eb373

20 files changed

+193
-181
lines changed

docs/cpp/thread.md

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,72 +18,73 @@ manager: "ghogen"
1818
translation.priority.ht: ["cs-cz", "de-de", "es-es", "fr-fr", "it-it", "ja-jp", "ko-kr", "pl-pl", "pt-br", "ru-ru", "tr-tr", "zh-cn", "zh-tw"]
1919
---
2020
# thread
21+
2122
**Microsoft Specific**
22-
23-
The **thread** extended storage-class modifier is used to declare a thread local variable. For the portable equivalent in C++11, use the [thread_local](../cpp/storage-classes-cpp.md#thread_local) storage class specifier.
24-
25-
## Syntax
26-
27-
```
28-
29-
__declspec( thread ) declarator
30-
```
31-
32-
## Remarks
33-
Thread Local Storage (TLS) is the mechanism by which each thread in a multithreaded process allocates storage for thread-specific data. In standard multithreaded programs, data is shared among all threads of a given process, whereas thread local storage is the mechanism for allocating per-thread data. For a complete discussion of threads, see [Multithreading](../parallel/multithreading-support-for-older-code-visual-cpp.md).
34-
35-
Declarations of thread local variables must use [extended attribute syntax](../cpp/declspec.md) and the `__declspec` keyword with the **thread** keyword. For example, the following code declares an integer thread local variable and initializes it with a value:
36-
37-
```
23+
The **thread** extended storage-class modifier is used to declare a thread local variable. For the portable equivalent in C++11 and later, use the [thread_local](../cpp/storage-classes-cpp.md#thread_local) storage class specifier.
24+
25+
## Syntax
26+
27+
```
28+
__declspec( thread ) declarator
29+
```
30+
31+
## Remarks
32+
33+
Thread Local Storage (TLS) is the mechanism by which each thread in a multithreaded process allocates storage for thread-specific data. In standard multithreaded programs, data is shared among all threads of a given process, whereas thread local storage is the mechanism for allocating per-thread data. For a complete discussion of threads, see [Multithreading](../parallel/multithreading-support-for-older-code-visual-cpp.md).
34+
35+
Declarations of thread local variables must use [extended attribute syntax](../cpp/declspec.md) and the `__declspec` keyword with the **thread** keyword. For example, the following code declares an integer thread local variable and initializes it with a value:
36+
37+
```cpp
3838
__declspec( thread ) int tls_i = 1;
39-
```
40-
41-
You must observe these guidelines when declaring thread local objects and variables:
42-
43-
- You can apply the **thread** attribute only to class and data declarations and definitions; **thread** cannot be used on function declarations or definitions.
44-
45-
- The use of the **thread** attribute may interfere with [delay loading](../build/reference/linker-support-for-delay-loaded-dlls.md) of DLL imports**.**
46-
47-
- On XP systems, `thread` may not function correctly if a DLL uses __declspec(thread) data and it is loaded dynamically via LoadLibrary.
48-
49-
- You can specify the **thread** attribute only on data items with static storage duration. This includes global data objects (both **static** and `extern`), local static objects, and static data members of classes. You cannot declare automatic data objects with the **thread** attribute.
50-
51-
- You must use the **thread** attribute for the declaration and the definition of a thread local object, whether the declaration and definition occur in the same file or separate files.
52-
53-
- You cannot use the **thread** attribute as a type modifier.
54-
55-
- Because the declaration of objects that use the **thread** attribute is permitted, these two examples are semantically equivalent:
56-
57-
```
58-
// declspec_thread_2.cpp
59-
// compile with: /LD
60-
__declspec( thread ) class B {
61-
public:
62-
int data;
63-
} BObject; // BObject declared thread local.
64-
65-
class B2 {
66-
public:
67-
int data;
68-
};
69-
__declspec( thread ) B2 BObject2; // BObject2 declared thread local.
70-
```
71-
72-
- Standard C permits initialization of an object or variable with an expression involving a reference to itself, but only for objects of nonstatic extent. Although C++ normally permits such dynamic initialization of an object with an expression involving a reference to itself, this type of initialization is not permitted with thread local objects. For example:
73-
74-
```
75-
// declspec_thread_3.cpp
76-
// compile with: /LD
77-
#define Thread __declspec( thread )
78-
int j = j; // Okay in C++; C error
79-
Thread int tls_i = sizeof( tls_i ); // Okay in C and C++
80-
```
81-
82-
Note that a `sizeof` expression that includes the object being initialized does not constitute a reference to itself and is allowed in C and C++.
83-
84-
**END Microsoft Specific**
85-
86-
## See Also
87-
[__declspec](../cpp/declspec.md)
88-
[Keywords](../cpp/keywords-cpp.md)
89-
[Thread Local Storage (TLS)](../parallel/thread-local-storage-tls.md)
39+
```
40+
41+
You must observe these guidelines when declaring thread local objects and variables:
42+
43+
- You can apply the **thread** attribute only to class and data declarations and definitions; **thread** cannot be used on function declarations or definitions.
44+
45+
- The use of the **thread** attribute may interfere with [delay loading](../build/reference/linker-support-for-delay-loaded-dlls.md) of DLL imports.
46+
47+
- On XP systems, **thread** may not function correctly if a DLL uses __declspec(thread) data and it is loaded dynamically via LoadLibrary.
48+
49+
- You can specify the **thread** attribute only on data items with static storage duration. This includes global data objects (both **static** and **extern**), local static objects, and static data members of classes. You cannot declare automatic data objects with the **thread** attribute.
50+
51+
- You must use the **thread** attribute for the declaration and the definition of a thread local object, whether the declaration and definition occur in the same file or separate files.
52+
53+
- You cannot use the **thread** attribute as a type modifier.
54+
55+
- Because the declaration of objects that use the **thread** attribute is permitted, these two examples are semantically equivalent:
56+
57+
```cpp
58+
// declspec_thread_2.cpp
59+
// compile with: /LD
60+
__declspec( thread ) class B {
61+
public:
62+
int data;
63+
} BObject; // BObject declared thread local.
64+
65+
class B2 {
66+
public:
67+
int data;
68+
};
69+
__declspec( thread ) B2 BObject2; // BObject2 declared thread local.
70+
```
71+
72+
- Standard C permits initialization of an object or variable with an expression involving a reference to itself, but only for objects of nonstatic extent. Although C++ normally permits such dynamic initialization of an object with an expression involving a reference to itself, this type of initialization is not permitted with thread local objects. For example:
73+
74+
```cpp
75+
// declspec_thread_3.cpp
76+
// compile with: /LD
77+
#define Thread __declspec( thread )
78+
int j = j; // Okay in C++; C error
79+
Thread int tls_i = sizeof( tls_i ); // Okay in C and C++
80+
```
81+
82+
Note that a **sizeof** expression that includes the object being initialized does not constitute a reference to itself and is allowed in C and C++.
83+
84+
**END Microsoft Specific**
85+
86+
## See Also
87+
88+
[__declspec](../cpp/declspec.md)
89+
[Keywords](../cpp/keywords-cpp.md)
90+
[Thread Local Storage (TLS)](../parallel/thread-local-storage-tls.md)
Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Visual C++ Language Reference (C++/CX) | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "12/30/2016"
4+
ms.date: "09/15/2017"
55
ms.technology: "cpp-windows"
66
ms.reviewer: ""
77
ms.suite: ""
@@ -14,35 +14,27 @@ ms.author: "ghogen"
1414
manager: "ghogen"
1515
---
1616
# Visual C++ Language Reference (C++/CX)
17-
C++/CX is a set of extensions to the C++ language that enable the creation of Windows apps and Windows Runtime components in an idiom that is as close as possible to modern C++. Use C++/CX to write Windows apps and components in native code that easily interact with Visual C#, Visual Basic, and JavaScript, and other languages that support the Windows Runtime. In those rare cases that require direct access to the raw COM interfaces, or non-exceptional code, you can use the [Windows Runtime C++ Template Library (WRL)](../windows/windows-runtime-cpp-template-library-wrl.md).
18-
19-
The new model represents the next generation of native C++ programming on Windows. By using it, you can create:
20-
21-
- C++ Windows apps that use XAML to define the user interface and use the native stack. For more information, see [Create a "hello world" app in C++ (Windows 10)](http://msdn.microsoft.com/library/windows/apps/dn996906.aspx).
22-
23-
- C++ Windows Runtime components that can be consumed by JavaScript-based Windows apps. For more information, see [Creating Windows Runtime Components in C++](/MicrosoftDocs/windows-uwp/blob/docs/windows-apps-src/winrt-components/creating-windows-runtime-components-in-cpp.md).
24-
25-
- Windows DirectX games and graphics-intensive apps. For more information, see [Create a simple Universal Windows Platform (UWP) Game with DirectX](http://msdn.microsoft.com/library/windows/apps/xaml/mt210793.aspx).
26-
27-
## Related articles
28-
29-
|||
30-
|-|-|
31-
|[Quick Reference](../cppcx/quick-reference-c-cx.md)|Table of keywords and operators for C++/CX.|
32-
|[Type System](../cppcx/type-system-c-cx.md)|Describes basic C++/CX types and programming constructs, and how to utilize C++/CX to consume and create Windows Runtime types.|
33-
|[Building apps and libraries](../cppcx/building-apps-and-libraries-c-cx.md)|Discusses how to use the IDE to build apps and link to static libraries aned DLLs.|
34-
|[Interoperating with Other Languages](../cppcx/interoperating-with-other-languages-c-cx.md)|Discusses how components that are written by using C++/CX can be used with components that are written in JavaScript, any managed language, or the [!INCLUDE[cppwrl](../cppcx/includes/cppwrl-md.md)].|
35-
|[Threading and Marshaling](../cppcx/threading-and-marshaling-c-cx.md)|Discusses how to specify the threading and marshaling behavior of components that you create.|
36-
|[Namespaces Reference](../cppcx/namespaces-reference-c-cx.md)|Reference documentation for the default namespace, the Platform namespace, Platform::Collections, and related namespaces.|
37-
|[CRT functions not supported in Universal Windows Platform apps](../cppcx/crt-functions-not-supported-in-universal-windows-platform-apps.md)|Lists the CRT functions that are not available for use in Windows Runtime apps.|
38-
|[How to guides for Windows 10 apps](http://msdn.microsoft.com/library/windows/apps/xaml/mt244352.aspx)|Provides high-level guidance about Windows 10 apps and links to more information.|
39-
40-
1. [C++/CX Part 0 of \[n\]: An Introduction](http://blogs.msdn.com/b/vcblog/archive/2012/08/29/cxxcxpart00anintroduction.aspx)
41-
42-
2. [C++/CX Part 0 of \[n\]: An Introduction](http://blogs.msdn.com/b/vcblog/archive/2012/08/29/cxxcxpart00anintroduction.aspx)
43-
44-
3. [C++/CX Part 2 of \[n\]: Types That Wear Hats](http://blogs.msdn.com/b/vcblog/archive/2012/09/17/cxxcxpart02typesthatwearhats.aspx)
45-
46-
4. [C++/CX Part 3 of \[n\]: Under Construction](http://blogs.msdn.com/b/vcblog/archive/2012/10/05/cxxcxpart03underconstruction.aspx)
47-
48-
5. [C++/CX Part 4 of \[n\]: Static Member Functions](http://blogs.msdn.com/b/vcblog/archive/2012/10/19/cxxcxpart04staticmemberfunctions.aspx)
17+
18+
C++/CX is a set of extensions to the C++ language that enable the creation of Windows apps and Windows Runtime components in an idiom that is as close as possible to modern C++. Use C++/CX to write Windows apps and components in native code that easily interact with Visual C#, Visual Basic, and JavaScript, and other languages that support the Windows Runtime. In those rare cases that require direct access to the raw COM interfaces, or non-exceptional code, you can use the [Windows Runtime C++ Template Library (WRL)](../windows/windows-runtime-cpp-template-library-wrl.md).
19+
20+
The new model represents the next generation of native C++ programming on Windows. By using it, you can create:
21+
22+
- C++ Universal Windows Platform (UWP) apps that use XAML to define the user interface and use the native stack. For more information, see [Create a "hello world" app in C++ (UWP)](/windows/uwp/get-started/create-a-basic-windows-10-app-in-cpp).
23+
24+
- C++ Windows Runtime components that can be consumed by JavaScript-based Windows apps. For more information, see [Creating Windows Runtime Components in C++](/windows/uwp/winrt-components/creating-windows-runtime-components-in-cpp).
25+
26+
- Windows DirectX games and graphics-intensive apps. For more information, see [Create a simple UWP Game with DirectX](/windows/uwp/gaming/tutorial--create-your-first-metro-style-directx-game).
27+
28+
## Related articles
29+
30+
|||
31+
|-|-|
32+
|[Quick Reference](../cppcx/quick-reference-c-cx.md)|Table of keywords and operators for C++/CX.|
33+
|[Type System](../cppcx/type-system-c-cx.md)|Describes basic C++/CX types and programming constructs, and how to utilize C++/CX to consume and create Windows Runtime types.|
34+
|[Building apps and libraries](../cppcx/building-apps-and-libraries-c-cx.md)|Discusses how to use the IDE to build apps and link to static libraries aned DLLs.|
35+
|[Interoperating with Other Languages](../cppcx/interoperating-with-other-languages-c-cx.md)|Discusses how components that are written by using C++/CX can be used with components that are written in JavaScript, any managed language, or the [!INCLUDE[cppwrl](../cppcx/includes/cppwrl-md.md)].|
36+
|[Threading and Marshaling](../cppcx/threading-and-marshaling-c-cx.md)|Discusses how to specify the threading and marshaling behavior of components that you create.|
37+
|[Namespaces Reference](../cppcx/namespaces-reference-c-cx.md)|Reference documentation for the default namespace, the Platform namespace, Platform::Collections, and related namespaces.|
38+
|[CRT functions not supported in Universal Windows Platform apps](../cppcx/crt-functions-not-supported-in-universal-windows-platform-apps.md)|Lists the CRT functions that are not available for use in Windows Runtime apps.|
39+
|[How to guides for Windows 10 apps](http://msdn.microsoft.com/library/windows/apps/xaml/mt244352.aspx)|Provides high-level guidance about Windows 10 apps and links to more information.|
40+
|[C++/CX Part 0 of \[n\]: An Introduction](https://blogs.msdn.microsoft.com/vcblog/2012/08/29/ccx-part-0-of-n-an-introduction/)<br /><br />[C++/CX Part 1 of \[n\]: A Simple Class](https://blogs.msdn.microsoft.com/vcblog/2012/09/05/ccx-part-1-of-n-a-simple-class/)<br /><br />[C++/CX Part 2 of \[n\]: Types That Wear Hats](https://blogs.msdn.microsoft.com/vcblog/2012/09/17/ccx-part-2-of-n-types-that-wear-hats/)<br /><br />[C++/CX Part 3 of \[n\]: Under Construction](https://blogs.msdn.microsoft.com/vcblog/2012/10/05/ccx-part-3-of-n-under-construction/)<br /><br />[C++/CX Part 4 of \[n\]: Static Member Functions](https://blogs.msdn.microsoft.com/vcblog/2012/10/19/ccx-part-4-of-n-static-member-functions/)|An introductory Visual C++ blog series on C++/CX.|

docs/error-messages/compiler-errors-1/compiler-error-c2482.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2482 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "09/15/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -35,18 +35,21 @@ translation.priority.ht:
3535
- "zh-tw"
3636
---
3737
# Compiler Error C2482
38-
'identifier' : dynamic initialization of 'thread' data not allowed
39-
40-
Variables declared with the `thread` attribute cannot be initialized with an expression that requires run-time evaluation. A static expression is required to initialize `thread` data.
41-
42-
The following sample generates C2482:
43-
44-
```
45-
// C2482.cpp
46-
// compile with: /c
47-
#define Thread __declspec( thread )
48-
Thread int tls_i = tls_i; // C2482
49-
50-
int j = j; // OK in C++; C error
51-
Thread int tls_i = sizeof( tls_i ); // Okay in C and C++
52-
```
38+
39+
>'*identifier*' : dynamic initialization of 'thread' data not allowed
40+
41+
This error message is obsolete in Visual Studio 2015 and later versions. In previous versions, variables declared by using the `thread` attribute cannot be initialized with an expression that requires run-time evaluation. A static expression is required to initialize `thread` data.
42+
43+
## Example
44+
45+
The following sample generates C2482 in Visual Studio 2013 and earlier:
46+
47+
```cpp
48+
// C2482.cpp
49+
// compile with: /c
50+
#define Thread __declspec( thread )
51+
Thread int tls_i = tls_i; // C2482
52+
53+
int j = j; // OK in C++; C error
54+
Thread int tls_i = sizeof( tls_i ); // Okay in C and C++
55+
```

docs/error-messages/compiler-errors-1/compiler-error-c2483.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2483 | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "09/15/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
@@ -35,23 +35,26 @@ translation.priority.ht:
3535
- "zh-tw"
3636
---
3737
# Compiler Error C2483
38-
'identifier' : object with constructor or destructor cannot be declared 'thread'
39-
40-
Variables declared with the `thread` attribute cannot be initialized with a constructor or other expression that requires run-time evaluation. A static expression is required to initialize `thread` data.
41-
42-
## Example
43-
The following sample generates C2483.
44-
45-
```
46-
// C2483.cpp
47-
// compile with: /c
48-
__declspec(thread) struct A {
49-
A(){}
50-
~A(){}
38+
39+
>'*identifier*' : object with constructor or destructor cannot be declared 'thread'
40+
41+
This error message is obsolete in Visual Studio 2015 and later versions. In previous versions, variables declared with the `thread` attribute cannot be initialized with a constructor or other expression that requires run-time evaluation. A static expression is required to initialize `thread` data.
42+
43+
## Example
44+
45+
The following sample generates C2483 in Visual Studio 2013 and earlier versions.
46+
47+
```cpp
48+
// C2483.cpp
49+
// compile with: /c
50+
__declspec(thread) struct A {
51+
A(){}
52+
~A(){}
5153
} aa; // C2483 error
52-
53-
__declspec(thread) struct B {} b; // OK
54-
```
55-
56-
## See Also
57-
[thread](../../cpp/thread.md)
54+
55+
__declspec(thread) struct B {} b; // OK
56+
```
57+
58+
## See Also
59+
60+
[thread](../../cpp/thread.md)

0 commit comments

Comments
 (0)