a possibly similar question was discussed here In the response I provided, the links to SO topics discuss one possible method to avoid the hazard you mention:
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Generating unknown amount of data | 6 | 3163 | February 22, 2008 | |
| Occupancy and memory | 3 | 1636 | March 25, 2010 | |
| Management of threads | 3 | 1892 | March 28, 2010 | |
| Local memory usage | 5 | 1405 | July 9, 2010 | |
| temporary memory issues | 11 | 5538 | March 30, 2008 | |
| Thread Local variable | 1 | 1718 | September 23, 2009 | |
| Thread processing overhead | 2 | 515 | February 16, 2011 | |
| In-Place Memory Transfers (without temp buffers) | 1 | 754 | December 8, 2012 | |
| Calculating GPU Memory Requirement for 4096 CUDA Threads with Multiple 2D Arrays | 1 | 105 | November 30, 2024 | |
| number of threads and number of data | 2 | 1186 | July 16, 2009 |