Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have come across a problem where we have to take a decision between below mentioned choices:

1.A process is creating some X number of worker threads.These worker thread would create log file of specific length.
2.Create X number of processes and create log files of specific length by using those processes.

Which would be better Approach.

What I have tried:

This problem is given for the windows based environment.
Posted
Updated 1-Nov-17 10:27am
Comments
Richard MacCutchan 1-Nov-17 12:30pm    
Why not try both, add some code to time all the work, and see what you get?
jeron1 1-Nov-17 12:48pm    
Maybe some things discussed in this thread may help.
c++ - Multithreading vs multiprocessing[^]

I would use the first solution by knowning from experience, that a lot of threads arent faster in multithreading, because the overhead is slowing down. The great "but" is what resources your threads are working on. When you write at one disk even two processes can be slower than one, but when you fetch and compute remote data a solid amount of thread could better. Think about thread syncronization like on disk writing (write once and all) or network access.

So you need to finetune the thread count by testing. Important: Test with release code.

Tip: write clean and reusable code for the case that the tuning shows another approach than expected.
 
Share this answer
 
Assuming you need some kind of parallel execution (at least conceptually) then it strongly depends on the interaction between the different tasks. The more interaction is required the more I would suggest to use threads. On the other hand, if the interaction is minimal I would suggest to use different processes. You know threads communicates more simply and with less overhead while single thread processes provide a simpler execution model and could be, at least in principle, more reliable (my two cents).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900