Sign in to follow this  
CRACK123

optimizing problem - pthreads mutex lock and mkdir() function

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[i];

    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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this