How does the clock
function work behind the scene in a multithreading program?
AFAIK, the clock function provided by the C standard library could be used to measure the CPU time consumed by the running program, but how does this process work under the hood? Is the underlying hardware timer part of the CPU chip? If it's not, how does the clock know when the CPU is scheduled to run the current program? Since the clock
function only records the time consumption of each individual CPU that executes the current program. Meaning in a multi-threaded program, the returned value would be lower than the wall-clock time.
*Although I raised another question in What's the relationship between the real CPU frequency and the clock_t in C?, but actually, those are two different topics, so, I don't want to mix them up in one post.