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");
mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
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]

Create an account

Register a new account

• Forum Statistics

• Total Topics
628354
• Total Posts
2982229

• 10
• 9
• 11
• 24
• 11