Jump to content
  • Advertisement
Sign in to follow this  
CRACK123

optimizing problem - pthreads mutex lock and mkdir() function

This topic is 4245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to create a directory structure in my program but I make a mutex lock when I create a directory in my code. However at some point it takes about 718 seconds to break out of the lock. This is the code I have
for(int i = 0; i < (size - 1); i++)
{
    dirPath = dirPath + add + dir;

    if(opendir(dirPath.c_str()) == NULL)
    {
      TNF_PROBE_0(CreateDirectoryListLock, "dirLock", "lock probe");
      pthread_mutex_lock(&lockFile);
      mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
      pthread_mutex_unlock(&lockFile);
      TNF_PROBE_0(CreateDirectoryListUnLock, "dirUnLock", "lock probe");
    }
}



These are the results I get after whatever optimization I have tried - however I am running out of ideas of what to optimize to get all values in a few seconds or microseconds. I don't care about the errors of mkdir at the moment - especially if the directory exists so I am doing very optimistic creation of the directory. Is there anyway I can optimize the code further ? These are the results of the probing using TNFPROBE and TNFDUMP.
probe	 tnf_name: "CreateDirectoryListLock" tnf_string: "keys dirLock;file server.cpp;line 94;lock probe"
probe	 tnf_name: "CreateDirectoryListUnLock" tnf_string: "keys dirUnLock;file server.cpp;line 98;lock probe"
---------------- ---------------- ----- ----- ---------- --- ------------------------- ------------------------
    Elapsed (ms)       Delta (ms)   PID LWPID    TID     CPU Probe Name                Data / Description . . .
---------------- ---------------- ----- ----- ---------- --- ------------------------- ------------------------
        0.000000         0.000000 17114  2          2     - CreateDirectoryListLock  
        1.279800         1.279800 17114  2          2     - CreateDirectoryListUnLock
     1824.725000      1823.445200 17114  4          4     - CreateDirectoryListLock  
     1825.998900         1.273900 17114  4          4     - CreateDirectoryListUnLock
   720523.545500    718697.546600 17114  11         11    - CreateDirectoryListLock  
   720524.239100         0.693600 17114  12         12    - CreateDirectoryListLock  
   720525.418300         1.179200 17114  11         11    - CreateDirectoryListUnLock
   720526.842000         1.423700 17114  12         12    - CreateDirectoryListUnLock
   720529.132300         2.290300 17114  13         13    - CreateDirectoryListLock  
   720530.291600         1.159300 17114  13         13    - CreateDirectoryListUnLock



Thanks [Edited by - CRACK123 on October 9, 2006 1:17:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!