trying
This commit is contained in:
parent
dcbface9ba
commit
a72488734c
38
11/part2.c
38
11/part2.c
|
@ -27,19 +27,7 @@ void print_struc(struc *head) {
|
|||
}
|
||||
}
|
||||
|
||||
void* thread(void *data_void);
|
||||
|
||||
pthread_t create_thread(long nbr, int max) {
|
||||
pthread_t thread_id;
|
||||
data dt = {nbr, max};
|
||||
pthread_create(&thread_id, NULL, thread, &dt);
|
||||
pthread_join(thread_id, NULL);
|
||||
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
long count = 0;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
void blink(long nbr, int max) {
|
||||
for (; max > 0; max--) {
|
||||
|
@ -51,21 +39,12 @@ void blink(long nbr, int max) {
|
|||
int left = nbr / (pow(10, len / 2));
|
||||
nbr = nbr % (long)(pow(10, len / 2));
|
||||
|
||||
create_thread(left, max - 1);
|
||||
blink(left, max - 1);
|
||||
}
|
||||
else
|
||||
nbr *= 2024;
|
||||
}
|
||||
pthread_mutex_lock(&mutex);
|
||||
count++;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
void* thread(void *data_void) {
|
||||
data *dt = (data*)data_void;
|
||||
blink(dt->nbr, dt->max);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -84,23 +63,12 @@ int main(int argc, char **argv) {
|
|||
cur = cur->next;
|
||||
}
|
||||
|
||||
|
||||
//long len = lenght_struc(head);
|
||||
//pthread_t thread_id[len + 1];
|
||||
|
||||
pthread_mutex_init(&mutex, NULL);
|
||||
|
||||
cur = head;
|
||||
for (int i = 0; cur->next != NULL; i++) {
|
||||
create_thread(cur->nbr, 75);
|
||||
while (cur->next != NULL) {
|
||||
blink(cur->nbr, 75);
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
|
||||
//for (int i = 0; i < len; i++) {
|
||||
//pthread_join(thread_id[i], NULL);
|
||||
//}
|
||||
|
||||
printf("count: %ld\n", count);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue