By definition, multiple threads of a single program share their working directory. Do you know if there is a way to have each thread in a dedicated working dir ? Maybe a specific library ?
Note : target language is c++
This concept doesn't exist on every operating system, but it does for Linux and Mac OS at least.
On Linux, create your thread with clone
with CLONE_THREAD
and without CLONE_FS
. Alternatively, create a thread normally and use unshare
with CLONE_FS
. Then, use chdir
or fchdir
normally.
On Mac OS use pthread_chdir_np
or pthread_fchdir_np
. These calls have sparse documentation, but are available since 10.12. The Chromium source indicates that this concept exists since 10.5, but you have to use the syscall directly.
Most of the time you will want to prefer the *at
family of calls, but there are some situations where it isn't possible to use them--for example, connect
ing or bind
ing a Unix domain socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With