From 8b63cc049aa2faa0772d1956c743c33ef9e1b98c Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 23 Aug 2023 10:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E4=BB=BB=E5=8A=A1=E4=BA=92=E6=96=A5?= =?UTF-8?q?=E4=B8=8E=E5=90=8C=E6=AD=A5(=E4=BA=92=E6=96=A5=E9=94=81,=20?= =?UTF-8?q?=E8=AF=BB=E5=86=99=E9=94=81,=20=E6=9D=A1=E4=BB=B6=E5=8F=98?= =?UTF-8?q?=E9=87=8F,=20=E4=BF=A1=E5=8F=B7=E9=87=8F,=20=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E9=87=8F):=20=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day7/homework/h6.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/day7/homework/h6.c b/day7/homework/h6.c index c74be24..224478c 100644 --- a/day7/homework/h6.c +++ b/day7/homework/h6.c @@ -7,7 +7,7 @@ #include #include -pthread_mutex_t mutux = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; typedef struct node { @@ -21,7 +21,7 @@ void *find(void *data) { int n = 0; // 标识待查询内容在链表中的索引号 char *name = (char *)data; - pthread_mutex_lock(&mutux); + pthread_mutex_lock(&mutex); // 查询 Node *p = head->next; while (p != NULL) @@ -29,7 +29,7 @@ void *find(void *data) if (strcmp(p->name, name) == 0) { printf("%s 在链表的索引为 %d\n", name, n); - pthread_mutex_unlock(&mutux); + pthread_mutex_unlock(&mutex); return NULL; } @@ -38,7 +38,7 @@ void *find(void *data) p = p->next; } printf("%s 在链表中未找到\n", name); - pthread_mutex_unlock(&mutux); + pthread_mutex_unlock(&mutex); return NULL; } @@ -89,5 +89,7 @@ int main(int argc, char const *argv[]) pthread_join(t[i], NULL); } + pthread_mutex_destroy(&mutex); + return 0; }