in reply to Re: Store last value of for loop
in thread Store last value of for loop

There are n number of articles and each articles contains m number of files. How to use threading concept and print the values sequentially. Using of for loops on each 'n' number of articles it prints value from 1 to m files. second articles initializes again to 1 and print m files. The problem is n articles and m number of files within n articles should print in sequential order.

Replies are listed 'Best First'.
Re^3: Store last value of for loop
by jethro (Monsignor) on Jan 15, 2009 at 14:06 UTC

    If you want to print something sequential it makes no sense using threads for that particular problem. You are very vague and abstract about your problem. Why do you need the threads? How big can n and m get?

    If you need threads for some other reason then you might store the output from each thread in a different variable (if it fits in memory) and combine them later, or store the output in a different file per thread.

    Or use only one file with the number of the thread prepended on each line. Then simply sort the file and print. But for this you need file locking or some other signaling mechanism so that two threads don't write to the file at the same time. If you have a database engine, the same can be done without locking problems by using the thread number as key