Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:44:22+00:00 2026-06-07T18:44:22+00:00

Is there any thread safe implementation of nftw() in C/C++? In the documentation it

  • 0

Is there any thread safe implementation of nftw() in C/C++? In the documentation it says

“The nftw() function need not be thread-safe.”

I’m going to use nftw for a recursive delete function to walk through the directory structure in a multi threaded application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:44:24+00:00Added an answer on June 7, 2026 at 6:44 pm

    One trivial way to make a non-thread-safe function thread-safe is to wrap it in a function that obtains a lock before calling it, and always call it through this wrapper. In general you would need to copy out the results before unlocking, but nftw does not yield any results that would need to be copied after it returns. A few caveats though:

    1. This will of course prevent all parallelism when multiple threads want to use the interface.

    2. One option to nftw makes it chdir to each directory it walks. This is a very bad thing for a multi-threaded app (since the current directory is shared by all threads), so you should avoid using this option.

    On POSIX 2008 systems with the openat and related interfaces, it’s pretty trivial to implement your own equivalent of nftw without any chdir usage or pathname length limitations, so you might be better off just writing your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that singleton classes are inherently not thread-safe. But is there any way
For being thread safe do we need to assign function parameters to the local
Is there any way I can have thread-safe coroutines along with boost::asio? I want
Is there any good example of poller class? Thread safe with wait handles, with
First, I'm assuming that calling any function of std::chrono is guaranteed to be thread-safe
Is the .NET class System.Net.CookieContainer thread safe? -- Update: Turnkey answered-- Is there any
Are there any concurrency problems with one thread reading from one index of an
Is there any way I can have a thread branch off into its own
Are there any race condition issues when using NSNotifications within a single thread? Here
Is there any known implementation of Haskell MVar in C? There is an example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.