0

I am working on a project for University which requires me to use POSIX threads in C. I have done most of the work but I have two major problems I can't seem to work out.

  • First, I need to calculate the time a thread has been running. I can't figure which methods or functions I need to use for it.
  • Second I have to display the attributes of each thread (created with pthread_attr_init()) as a message on the screen.

Any help appreciated. Thank you.

  • Can you provide information as to what you are confused with, specifically? Figuring out a time delta is simple, so I'm sure there's something other than subtraction that is throwing you off. – dho Jan 09 '15 at 23:45
  • I am confused towards which functions I should use to do it. I am not very familiar with C as a programming language and I haven't found a satisfactory answer yet. – One_Step_Ahead Jan 10 '15 at 00:05
  • possible duplicate of [How do I measure time per thread in C?](http://stackoverflow.com/questions/27718464/how-do-i-measure-time-per-thread-in-c) – Jonathon Reinhart Jan 10 '15 at 00:13
  • You should ask one question at a time. Your first question is a duplicate of the one I've just linked to. – Jonathon Reinhart Jan 10 '15 at 00:14
  • I was searching for it but I did not find such a question, I was searching with wrong search terms apparently. Thank a lot anyways. – One_Step_Ahead Jan 10 '15 at 00:35

1 Answers1

0

For the first you can use getrusage() with the "this thread only" option.

For the second, use printf() to print the fields of your pthread attribute struct.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436