How to detect the number of threads i can & i should run?
<p>i have a 6th generation Intel i5 Processor (4 cores, 3 ghZ) and 8 gigabytes of RAM. Let's assume i need to create a text file which includes every number from 0 to 999999999. </p>

<p>How can  i make it faster? How many threads i should use? 4 or more than 4? How many threads i should run and why?</p>

<p>Due to the fact you're writing into the same file, you will need a lock in order for the text not to get garbled. If you're using a lock however, multi-threading or multi-processing won't make a difference as it will be writing sequentially.</p>

<p>Not using a lock will get a result much like this:</p>

<pre><code>1, 2, 3, 54,, ...
</code></pre>

<p>as one thread will write it's own and the other thread will write at the same time.</p>

python multithreading