I am laying in the framework for a tool that will generate a binary data table. I a plan on making this multithreaded to take full advantage of the 24 cores at my disposal. (I am estimating that the wall time for generation of the data will be about 50 days–in a single thread.). I have done this in the past using server/client design with socket communication as I needed to distributed this across multiple machines.
This time around, I am looking at a single machine/multi-threaded approach and am trying to figure out how to do this the right way.
The master thread will handle the assignment of tasks to each child thread and determining the offset into the allocated memory.
Each thread will write to a unique address range within the allocated memory. Because these blocks will never overlap between records, no two threads will ever attempt to write the same offset.
void computeRecord(void *taskInput)
{
struct TaskData *taskData = (TaskData *)(taskInput);
RecordData data;
// A huge long computation block to populate data
// (4-5 second run time)
long record_id = taskData->record_id;
char *buffer = taskData->start_buffer;
// mutex lock needed here ??
int n_bytes = sizeof(RecordData)
memcpy( (char *)(buffer+record_id*n_bytes), (char *)(&recordData) n_bytes);
// mutex unlock here ?
}
Long setup. Short question. Is the mutex necessary in this case?