You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merged PR 17061: Clarify current directory and relative path warnings
Existing text erroneously implied that the current directory is not thread safe. It also went too far in saying that relative path usage in multithreaded apps is "not supported". It is supported, but the results may not be what apps expect. Provide new guidance.
Copy file name to clipboardExpand all lines: sdk-api-src/content/winbase/nf-winbase-setcurrentdirectory.md
+11-2Lines changed: 11 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -90,8 +90,17 @@ Each process has a single current directory made up of two parts:
90
90
<li>A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\<i>servername</i>\<i>sharename</i>)</li>
91
91
<li>A directory on the disk designator</li>
92
92
</ul>
93
-
Multithreaded applications and shared library code should not use the
94
-
<b>SetCurrentDirectory</b> function and should avoid using relative path names. The current directory state written by the <b>SetCurrentDirectory</b> function is stored as a global variable in each process, therefore multithreaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value. This limitation also applies to the <ahref="/windows/desktop/api/winbase/nf-winbase-getcurrentdirectory">GetCurrentDirectory</a> and <ahref="/windows/desktop/api/fileapi/nf-fileapi-getfullpathnamea">GetFullPathName</a> functions. The exception being when the application is guaranteed to be running in a single thread, for example parsing file names from the command line argument string in the main thread prior to creating any additional threads. Using relative path names in multithreaded applications or shared library code can yield unpredictable results and is not supported.
93
+
94
+
The current directory is shared by all threads of the process:
95
+
If one thread changes the current directory, it affects all threads
96
+
in the process.
97
+
Multithreaded applications and shared library code should avoid
98
+
calling the <b>SetCurrentDirectory</b> function due to the risk of
99
+
affecting relative path calculations being performed by other threads.
100
+
Conversely,
101
+
multithreaded applications and shared library code should avoid
102
+
using relative paths so that they are unaffected by changes to the
103
+
current directory performed by other threads.
95
104
96
105
In Windows 8 and Windows Server 2012, this function is supported by the following technologies.
0 commit comments