954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Threading (multi threading) in Linux

Hello,

I want to create a very simple program to test threading. Example

int main () {

   char option = 'a';
   int run = 1;

   while ( option != 'x' ) {
      option = getch ();
      /* some code that changes run */

     /* thread ? */
   }

}


Now I wanted a thread to run every X seconds, displaying some message (like the value of the run variable).

How can this be accomplished?

Thanks for your help.

Mr.
Newbie Poster
18 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Hello,

some hits, tips, tricks...

Thanks.

Mr.
Newbie Poster
18 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Well it's working Ok. managed to work it out from examples.

1) Just created a thread with

pthread_t newThreadName;

2) Then "attached" (not sure to what's the expression) the newThreadName to a function with pthread_create

3) Then just added some timing logic within a loop in the new function.

...

If someone knows other ways please say so.

Thank.

Mr.
Newbie Poster
18 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You