IThread, is new thread per async call preferred, or one thread for all async calls | developer.brewmp.com IThread, is new thread per async call preferred, or one thread for all async calls | developer.brewmp.com

Developer

IThread, is new thread per async call preferred, or one thread for all async calls

Forums:

Hello all,

I am using IThread in my project. it works pretty well so far. I have at least three threads, one for timer, one for event handling ...

I have some other async functions which need thread too. Should I create a new thread for each async function (release after it's done)? or only one thread to handle all of them according to current state (in a loop)?

Is IThread lightweight and efficient enough that I can create as many threads as I want when I have enough memory? or there is limitation that too many threads will slow down performance?

Thanks

If all can run in a single thread, then keep the thread alive for required time.

If all can run in a single thread, then keep the thread alive for required time.

Do you mean I should use as less number of threads as possible?

Do you mean I should use as less number of threads as possible?

Ideally yes.. using less threads helps to keep your app simple.
Generally if you dont' have any other option, only then use threads.

Ideally yes.. using less threads helps to keep your app simple.
Generally if you dont' have any other option, only then use threads.

Using threads cannot be avoid in my project. I call yield in each thread to make sure no thread take CPU for too long.
My concern is performance. will more threads make performance much worse than less threads?

Using threads cannot be avoid in my project. I call yield in each thread to make sure no thread take CPU for too long.
My concern is performance. will more threads make performance much worse than less threads?

Icewater wrote:Using threads cannot be avoid in my project. I call yield in each thread to make sure no thread take CPU for too long.
My concern is performance. will more threads make performance much worse than less threads?
Threads in BREW are relatively cheap, due to the cooperative nature of the scheduler. Consequently they will not, in themselves, dramatically affect performance. However, each thread requires its own stack, so you should keep the memory overhead in mind.
Ben

Icewater wrote:Using threads cannot be avoid in my project. I call yield in each thread to make sure no thread take CPU for too long.
My concern is performance. will more threads make performance much worse than less threads?
Threads in BREW are relatively cheap, due to the cooperative nature of the scheduler. Consequently they will not, in themselves, dramatically affect performance. However, each thread requires its own stack, so you should keep the memory overhead in mind.
Ben

Thanks a lot, Ben.

Thanks a lot, Ben.