static void *producer(void *arg) { threadinf *inf = (threadinf*)arg; char *op; int i; long long int me = (long long int)pthread_self(); for (i = 0; i < ITERATIONS; i++) { // printf("PULL! %lld\n",me); item *it; qitem *qi = queue_get_item(inf->q); if (qi->cmd == NULL) qi->cmd = malloc(sizeof(item)); it = (item*)qi->cmd; it->n = i; it->thread = inf->thread; queue_push(inf->q,qi); // if (tries > 10) // printf("%lld, i=%d, tries=%d, index=%d\n",me, i, tries, index); // if ((i % 10000) == 0) // printf("pthr=%lld, i=%d\n",me, i); } return NULL; }
static void *producer(void *arg) { threadinf *inf = (threadinf*)arg; char *op; uint64_t i; long long int me = (long long int)pthread_self(); uint64_t val = 1; while (val < ITERATIONS) { // printf("PULL! %lld\n",me); item *it; qitem *qi = queue_get_item(inf->q); if (!qi) continue; if (qi->cmd == NULL) qi->cmd = calloc(1,sizeof(item)); if (qi->home != tls_reuseq) { printf("Item returned to wrong home!\n"); exit(1); } it = (item*)qi->cmd; // if (it->recycled) // printf("RECYCLED! %u %d\n",it->recycled, inf->thread); it->n = val++; it->thread = inf->thread; queue_push(inf->q,qi); // if (tries > 10) // printf("%lld, i=%d, tries=%d, index=%d\n",me, i, tries, index); // if ((i % 10000) == 0) // printf("pthr=%lld, i=%d\n",me, i); } printf("Thread done %llu\n", tls_qsize); return NULL; }