| | |
How to get a thread's execution time
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
When you spawn the thread you pass a void user value!
Why not pass a boolean pointer! Loop while it is set and when false fall out of the thread loop. Don't forget your thread exit function for proper cleanup.
Or pass in a local index for that worker thread.
In application root cleanup.
Loop for up until all gThreadActive[] become clear or the clock runs out, whichever comes first.
If you use semaphores, use a single gThreadActive parameter and merely clear the bit!
Why not pass a boolean pointer! Loop while it is set and when false fall out of the thread loop. Don't forget your thread exit function for proper cleanup.
C++ Syntax (Toggle Plain Text)
void MyWorker( void *foo ) { bool *pbSignal = (bool *)foo; while (foo) { } }
Or pass in a local index for that worker thread.
C++ Syntax (Toggle Plain Text)
void MyWorker( void *foo ) { uint idx = (uint)foo; while ( gbAppActive == true ) { } gThreadActive[ idx ] = false; // Tell root that this thread is shut down }
In application root cleanup.
Loop for up until all gThreadActive[] become clear or the clock runs out, whichever comes first.
If you use semaphores, use a single gThreadActive parameter and merely clear the bit!
C++ Syntax (Toggle Plain Text)
LOCK(); gThreadActive ^= 1 << idx; UNLOCK();
•
•
Join Date: Sep 2008
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
When you spawn the thread you pass a void user value!
Why not pass a boolean pointer!
Wildgoose, I don't get what this last post has to offer to the discussion.
•
•
Join Date: Sep 2008
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
I don't understand what's so difficult about thread timing. If you want the thread to quit after a specified amount of time, then just compare current time with original thread entry time and exit when that difference is greater than some pre-determined amount of time.
NOTE: as mentioned in a previous post this issue can be solved in UNIX by using clock_gettime with the flag CLOCK_THREAD_CPUTIME_ID. I don't even need to save the start point because each thread's clock is set to 0 when it starts. I made the tests, 10 threads executing for 50 seconds in a core-duo processor, giving total time ~= 250 seconds, perfect for me!
I am still looking for a solution which can be applied cross-platform, or at least a similar solution for windows.
GetThreadTimes()
I have not used it and don't know if it will meet your needs. Did you overlook this thread?
I have not used it and don't know if it will meet your needs. Did you overlook this thread?
![]() |
Similar Threads
- using empty() with while loop gives maximum execution time error (PHP)
- Very Very Urgent...Need Code for Calculating Execution Time For Jsp Page (JSP)
- to find the execution time of a code (C)
- Maximum execution time exceeded. (PHP)
- Execution time(plz Help) (Shell Scripting)
- date time issue in JSP (JSP)
- calculate the execution time of a program (C)
Other Threads in the C++ Forum
- Previous Thread: opening a file
- Next Thread: c++ application deployment
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game generator getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






