Monday, April 25, 2005

RE: This will THREAD your brains...

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

1 comment:

Classic Car Seats said...

We supply new custom classic car seats for your classic sportscar in various configurations and designs. Whether you need a quality seat for a classic car restoration, a custom seat for a luxurious upgrade, or a high performance seat to meet the demands of racing or offroad motorsports we have the perfect seat for you. Get your classic car seats at http://www.classiccarseats.com.