Hi,
Finally, i finished this bare-bones implementation on the THREAD'ed problem. You can find the tarball here.
Unzip it & follow whats inside README. This is my interpretation of the result...
//pthread_join(thread_1, NULL);
//pthread_join(thread_2, NULL);
Since i dont allowed the threads to finish (as the problem didn't mentioned it), the value of "integer"...
//global variable
int integer=0;
...varies between 0 to 8. Most of the time, its zero as the "main" thread finishes before any of the children threads. If the first thread gets CPU, the value goes to 3 & in the best case, it goes to 8.
BUT, it does not goes beyond 8.
### Outputs ###
Makentoo thread # ./plusplus
Value of Integer before creating threads = 0
Creating Thread-1
Creating Thread-2
Inside Thread 1, integer = 1, loop=1
Inside Thread 1, integer = 2, loop=2
Inside Thread 1, integer = 3, loop=3
Value of Integer after creating threads = 3
Makentoo thread # ./plusplus
Value of Integer before creating threads = 0
Creating Thread-1
Creating Thread-2
Value of Integer after creating threads = 0
Makentoo thread # ./plusplus
Value of Integer before creating threads = 0
Creating Thread-1
Creating Thread-2
Value of Integer after creating threads = 0
...thats it!
For any comments/suggestions/flames...
http://makuchaku.blogspot.com
mayank[dot]gnu[at]gmail[dot]com
Monday, April 25, 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment