I am using threads to increase the speed of my program.
As a result I now have a 8 bitset<UINT64_MAX>
bitsets. I plan on creating 8 separate threads, each of which are responsible for setting and checking the bitset they own, which is defined by an index passed to each thread.
Given that they are accessing and modifying the same bitset array, do I need to use mutexes?
Here is an example of my code:
#define NUM_CORES 8
class MyBitsetClass {
public:
bitset<UINT64_MAX> bitsets[NUM_CORES];
thread threads[NUM_CORES];
void init() {
for (uint8_t i = 0; i < NUM_CORES; i++) {
threads[i] = thread(&MyBitsetClass::thread_handler, this, i);
}
... do other stuff
}
void thread_handler(uint8_t i){
// 2 threads are never passed the same i value so they are always
// modifying their 'own' bitset. do I need a mutex?
bitsets[i].set(some_index);
}
}