question about clock()

T

timfield

If I have a program with threads running in parallel and I use clock()
to time segments of code, will that time include processor time of all
threads in the process, or just the calling thread?
 
K

Keith Thompson

If I have a program with threads running in parallel and I use clock()
to time segments of code, will that time include processor time of all
threads in the process, or just the calling thread?

I don't know. Standard C doesn't support threads, so the standard's
description of clock() doesn't distinguish between threads, processes,
etc.

Check your system's documentation, or try a newsgroup for your system.
 
J

Jordan Abel

If I have a program with threads running in parallel and I use clock()
to time segments of code, will that time include processor time of all
threads in the process, or just the calling thread?

It appears to do it across the whole process on my system, but threads
aren't in standard C, so who knows.
 
K

Keith Thompson

Michael said:
Hi, just tested it and it seems to time all the threads on the process.

You just tested what? Read <http://cfaj.freeshell.org/google/>.

This means that it applies to all the threads in the process *on your
system*. That may or may not be of any use to anyone else.

Standard C doesn't support threads, so there's no meaningful way to
answer the original question in the context of this newsgroup. Some
particular systems or secondary standards might provide a meaningful
answer (for example, I suspect the POSIX standard specifies this), but
that's a question for a different newsgroup, perhaps
comp.programming.threads or comp.unix.programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top