Имеем 1очередь работ, 5 нитей запускаемых вот с таким кодом
pthread_mutex_t mutexsum;
pthread_mutex_init(&mutexsum, NULL);
while (!jobsQueue.empty()) {
pthread_mutex_lock(&mutexsum);
first = jobsQueue.front();
jobsQueue.pop();
second = jobsQueue.front();
jobsQueue.pop();
pthread_mutex_unlock(&mutexsum);
colors1 = renderPixelParallell(first);
colors2 = renderPixelParallell(second);
pthread_mutex_lock(&mutexsum);
imageData[first[2]*3] = colors1.x;
imageData[first[2]*3+1] = colors1.y;
imageData[first[2]*3+2] = colors1.z;
imageData[second[2]*3] = colors1.x;
imageData[second[2]*3+1] = colors1.y;
imageData[second[2]*3+2] = colors1.z;
pthread_mutex_unlock(&mutexsum);
}
pthread_mutex_destroy(&mutexsum);
pthread_exit(NULL);