in reply to Re^2: Store last value of for loop
in thread Store last value of for loop
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
|
|---|