|
1 | | ---- |
2 | | -title: "threading (C++) | Microsoft Docs" |
3 | | -ms.custom: "" |
4 | | -ms.date: "11/04/2016" |
5 | | -ms.technology: ["cpp-windows"] |
6 | | -ms.topic: "reference" |
7 | | -f1_keywords: ["vc-attr.threading"] |
8 | | -dev_langs: ["C++"] |
9 | | -helpviewer_keywords: ["threading attribute"] |
10 | | -ms.assetid: 9b558cd6-fbf0-4602-aed5-31c068550ce3 |
11 | | -author: "mikeblome" |
12 | | -ms.author: "mblome" |
13 | | -ms.workload: ["cplusplus", "uwp"] |
14 | | ---- |
15 | | -# threading (C++) |
16 | | -Specifies the threading model for a COM object. |
17 | | - |
18 | | -## Syntax |
19 | | - |
20 | | -``` |
21 | | - |
22 | | - [ threading( |
23 | | - model=enumeration |
24 | | -) ] |
25 | | -``` |
26 | | - |
27 | | -#### Parameters |
28 | | - ***model*** (optional) |
29 | | - One of the following threading models: |
30 | | - |
31 | | -- **apartment** (apartment threading) |
32 | | - |
33 | | -- **neutral** (.NET Framework components with no user interface) |
34 | | - |
35 | | -- **single** (simple threading) |
36 | | - |
37 | | -- **free** (free threading) |
38 | | - |
39 | | -- **both** (apartment and free threading) |
40 | | - |
41 | | - The default value is **apartment**. |
42 | | - |
43 | | -## Remarks |
44 | | - The **threading** C++ attribute does not appear in the generated .idl file but will be used in the implementation of your COM object. |
45 | | - |
46 | | - In ATL projects, If the [coclass](../windows/coclass.md) attribute is also present, the threading model specified by *model* is passed as the template parameter to the [CComObjectRootEx](../atl/reference/ccomobjectrootex-class.md) class, inserted by the **coclass** attribute. |
47 | | - |
48 | | - The **threading** attribute also guards access to an [event_source](../windows/event-source.md). |
49 | | - |
50 | | -## Example |
51 | | - See the [licensed](../windows/licensed.md) example for a sample use of **threading**. |
52 | | - |
53 | | -## Requirements |
54 | | - |
55 | | -### Attribute Context |
56 | | - |
57 | | -||| |
58 | | -|-|-| |
59 | | -|**Applies to**|**class**, `struct`| |
60 | | -|**Repeatable**|No| |
61 | | -|**Required attributes**|**coclass**| |
62 | | -|**Invalid attributes**|None| |
63 | | - |
64 | | - For more information about the attribute contexts, see [Attribute Contexts](../windows/attribute-contexts.md). |
65 | | - |
66 | | -## See Also |
67 | | - [COM Attributes](../windows/com-attributes.md) |
68 | | - [Typedef, Enum, Union, and Struct Attributes](../windows/typedef-enum-union-and-struct-attributes.md) |
69 | | - [Class Attributes](../windows/class-attributes.md) |
70 | | - [Multithreading Support for Older Code (Visual C++)](../parallel/multithreading-support-for-older-code-visual-cpp.md) |
71 | | - [Neutral Apartments](http://msdn.microsoft.com/library/windows/desktop/ms681813) |
| 1 | +--- |
| 2 | +title: "threading (C++) | Microsoft Docs" |
| 3 | +ms.custom: "" |
| 4 | +ms.date: "11/04/2016" |
| 5 | +ms.technology: ["cpp-windows"] |
| 6 | +ms.topic: "reference" |
| 7 | +f1_keywords: ["vc-attr.threading"] |
| 8 | +dev_langs: ["C++"] |
| 9 | +helpviewer_keywords: ["threading attribute"] |
| 10 | +ms.assetid: 9b558cd6-fbf0-4602-aed5-31c068550ce3 |
| 11 | +author: "mikeblome" |
| 12 | +ms.author: "mblome" |
| 13 | +ms.workload: ["cplusplus", "uwp"] |
| 14 | +--- |
| 15 | +# threading (C++) |
| 16 | +Specifies the threading model for a COM object. |
| 17 | + |
| 18 | +## Syntax |
| 19 | + |
| 20 | +``` |
| 21 | +[ threading( |
| 22 | + model=enumeration |
| 23 | +) ] |
| 24 | +``` |
| 25 | + |
| 26 | +### Parameters |
| 27 | + *model* (optional) |
| 28 | + One of the following threading models: |
| 29 | + |
| 30 | +- `apartment` (apartment threading) |
| 31 | + |
| 32 | +- `neutral` (.NET Framework components with no user interface) |
| 33 | + |
| 34 | +- `single` (simple threading) |
| 35 | + |
| 36 | +- `free` (free threading) |
| 37 | + |
| 38 | +- `both` (apartment and free threading) |
| 39 | + |
| 40 | + The default value is `apartment`. |
| 41 | + |
| 42 | +## Remarks |
| 43 | + The **threading** C++ attribute does not appear in the generated .idl file but will be used in the implementation of your COM object. |
| 44 | + |
| 45 | + In ATL projects, If the [coclass](../windows/coclass.md) attribute is also present, the threading model specified by *model* is passed as the template parameter to the [CComObjectRootEx](../atl/reference/ccomobjectrootex-class.md) class, inserted by the `coclass` attribute. |
| 46 | + |
| 47 | + The **threading** attribute also guards access to an [event_source](../windows/event-source.md). |
| 48 | + |
| 49 | +## Example |
| 50 | + See the [licensed](../windows/licensed.md) example for a sample use of **threading**. |
| 51 | + |
| 52 | +## Requirements |
| 53 | + |
| 54 | +### Attribute Context |
| 55 | + |
| 56 | +||| |
| 57 | +|-|-| |
| 58 | +|**Applies to**|**class**, **struct**| |
| 59 | +|**Repeatable**|No| |
| 60 | +|**Required attributes**|**coclass**| |
| 61 | +|**Invalid attributes**|None| |
| 62 | + |
| 63 | + For more information about the attribute contexts, see [Attribute Contexts](../windows/attribute-contexts.md). |
| 64 | + |
| 65 | +## See Also |
| 66 | + [COM Attributes](../windows/com-attributes.md) |
| 67 | + [Typedef, Enum, Union, and Struct Attributes](../windows/typedef-enum-union-and-struct-attributes.md) |
| 68 | + [Class Attributes](../windows/class-attributes.md) |
| 69 | + [Multithreading Support for Older Code (Visual C++)](../parallel/multithreading-support-for-older-code-visual-cpp.md) |
| 70 | + [Neutral Apartments](http://msdn.microsoft.com/library/windows/desktop/ms681813) |
0 commit comments