Thread management / organization in parallel processing?
Posted: Mon Dec 06, 2010 1:36 pm
Hi all,
I have been redesigning my program and now working on thread management. Just some basic questions which need your suggestions:
Suppose my computer has n processors (cores) and I always need to create one thread for common tasks such as listening keyboard and starting / controlling other threads:
1) How many threads should I create for move computing? n or (n-1) or smaller?
2) How to communicate between computing threads and common task thread?
From common task thread, I can start / stop / give tasks computing threads (by setting up task then wake them up) - I am not worry much about those code.
However, after completing computing, my computing threads have to do the move by calling functions to modify directly the main data structure (store as global data or in common task thread) - that point I want to improve.
Is there any ways less "dirty" to do that? (say, the main data structure should be maintained by one thread only)?
3) How to implement self play function which helps program to play both sides until the end (without using any other program)? (I don't want recursive calling - too many)
(I know that I can solve 2 above problems by implementing something similar to event system but still worry about performance (it may require other "hard working thread" to maintain event only) and wonder if there is any other solution).
Thanks a lot for any idea / suggestion
I have been redesigning my program and now working on thread management. Just some basic questions which need your suggestions:
Suppose my computer has n processors (cores) and I always need to create one thread for common tasks such as listening keyboard and starting / controlling other threads:
1) How many threads should I create for move computing? n or (n-1) or smaller?
2) How to communicate between computing threads and common task thread?
From common task thread, I can start / stop / give tasks computing threads (by setting up task then wake them up) - I am not worry much about those code.
However, after completing computing, my computing threads have to do the move by calling functions to modify directly the main data structure (store as global data or in common task thread) - that point I want to improve.
Is there any ways less "dirty" to do that? (say, the main data structure should be maintained by one thread only)?
3) How to implement self play function which helps program to play both sides until the end (without using any other program)? (I don't want recursive calling - too many)
(I know that I can solve 2 above problems by implementing something similar to event system but still worry about performance (it may require other "hard working thread" to maintain event only) and wonder if there is any other solution).
Thanks a lot for any idea / suggestion