<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:18:37 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CDRIVER-3635] Thread creation on Windows should use _beginthreadex</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-3635</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Currently, CreateThread is used as the primitive to create threads on Windows, defined here:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/blob/r1.17/src/common/common-thread-private.h#L58&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/blob/r1.17/src/common/common-thread-private.h#L58&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My understanding is that _beginthreadex is a wrapper around CreateThread to ensure it is safe to use the C runtime. The &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createthread&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;documentation for CreateThread&lt;/a&gt; states:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multithreaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This is additionally stated in &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/procthread/creating-threads&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/procthread/creating-threads&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The MyThreadFunction function avoids the use of the C run-time library (CRT), as many of its functions are not thread-safe, particularly if you are not using the multithreaded CRT. If you would like to use the CRT in a ThreadProc function, use the _beginthreadex function instead.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Though &lt;a href=&quot;https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;docs for the CRT library&lt;/a&gt; state: &quot;All versions of the CRT support multi-threaded development&quot;, so I believe on Windows 10, where we are linking against the Universal CRT shipped with Windows, this may not be an observable issue.&lt;/p&gt;

&lt;p&gt;Other evidence:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;libuv and cpython both use _beginthreadex to create threads on Windows&lt;/li&gt;
	&lt;li&gt;this stack overflow discussion: &lt;a href=&quot;https://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;As an aside, we&apos;re using the wrong function signature for CreateThread anyway. Our thread functions have the pthread signature:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;static void *&lt;br/&gt;
 _mongoc_topology_run_background (void *data)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;CreateThread expects the thread function to match the signature:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;DWORD WINAPI ThreadProc(&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  _In_ LPVOID lpParameter&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms686736(v=vs.85)?redirectedfrom=MSDN&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;The docs for ThreadProc&lt;/a&gt; say:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread. Code that does this is common, but it can crash on 64-bit Windows.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;So that slightly worries me. If we need to fix this anyway, we&apos;d might as well use the recommended thread creation function.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1329034">CDRIVER-3635</key>
            <summary>Thread creation on Windows should use _beginthreadex</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13201">Fixed</resolution>
                                        <assignee username="kevin.albertson@mongodb.com">Kevin Albertson</assignee>
                                    <reporter username="kevin.albertson@mongodb.com">Kevin Albertson</reporter>
                        <labels>
                            <label>platform-problems</label>
                    </labels>
                <created>Sat, 25 Apr 2020 14:41:14 +0000</created>
                <updated>Sat, 28 Oct 2023 11:28:47 +0000</updated>
                            <resolved>Thu, 7 May 2020 01:07:51 +0000</resolved>
                                                    <fixVersion>1.17.0-beta2</fixVersion>
                    <fixVersion>1.17.0</fixVersion>
                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="3106176" author="xgen-internal-githook" created="Mon, 25 May 2020 21:14:14 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@mongodb.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3635&quot; title=&quot;Thread creation on Windows should use _beginthreadex&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3635&quot;&gt;&lt;del&gt;CDRIVER-3635&lt;/del&gt;&lt;/a&gt; fix more thread func decls&lt;br/&gt;
Branch: r1.17&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/0f5b1632e8f771900415cd76f63a397c16d927b5&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/0f5b1632e8f771900415cd76f63a397c16d927b5&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3106174" author="xgen-internal-githook" created="Mon, 25 May 2020 21:14:10 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@10gen.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3635&quot; title=&quot;Thread creation on Windows should use _beginthreadex&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3635&quot;&gt;&lt;del&gt;CDRIVER-3635&lt;/del&gt;&lt;/a&gt; use _beginthreadex, not CreateThread&lt;/p&gt;

&lt;p&gt;Use correct calling convention in thread functions.&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3634&quot; title=&quot;Windows thread handles are leaked&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3634&quot;&gt;&lt;del&gt;CDRIVER-3634&lt;/del&gt;&lt;/a&gt; close thread handles after joining.&lt;br/&gt;
Branch: r1.17&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/d47399cb8a885c538f5446b71ace9655e215454f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/d47399cb8a885c538f5446b71ace9655e215454f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3073056" author="xgen-internal-githook" created="Thu, 7 May 2020 01:28:42 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@mongodb.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3635&quot; title=&quot;Thread creation on Windows should use _beginthreadex&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3635&quot;&gt;&lt;del&gt;CDRIVER-3635&lt;/del&gt;&lt;/a&gt; fix more thread func decls&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/775e50961893da4185f7bd69d9159599c5f5f091&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/775e50961893da4185f7bd69d9159599c5f5f091&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3073045" author="xgen-internal-githook" created="Thu, 7 May 2020 01:06:56 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@10gen.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3635&quot; title=&quot;Thread creation on Windows should use _beginthreadex&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3635&quot;&gt;&lt;del&gt;CDRIVER-3635&lt;/del&gt;&lt;/a&gt; use _beginthreadex, not CreateThread&lt;/p&gt;

&lt;p&gt;Use correct calling convention in thread functions.&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3634&quot; title=&quot;Windows thread handles are leaked&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3634&quot;&gt;&lt;del&gt;CDRIVER-3634&lt;/del&gt;&lt;/a&gt; close thread handles after joining.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/bedfc0157f2d0a88c463086915426546b0f633b3&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/bedfc0157f2d0a88c463086915426546b0f633b3&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hx533z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>