MCPcopy Create free account
hub / github.com/MultithreadedJSBook/code-samples / main

Function main

ch1-c-threads/happycoin-threads.c:65–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63#define THREAD_COUNT 4
64
65int main() {
66 pthread_t thread [THREAD_COUNT];
67
68 int attempts = 10000000/THREAD_COUNT;
69 int count = 0;
70 for (int i = 0; i < THREAD_COUNT; i++) {
71 pthread_create(&thread[i], NULL, get_happycoins, &attempts);
72 }
73 for (int j = 0; j < THREAD_COUNT; j++) {
74 struct happy_result * result;
75 pthread_join(thread[j], (void **)&result);
76 count += result->count;
77 for (int k = 0; k < result->count; k++) {
78 printf("%" PRIu64 " ", result->nums[k]);
79 }
80 }
81 printf("\ncount %d\n", count);
82 return 0;
83}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected