/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes */ /* Multi-thread searching. Illustrates: thread cancellation, cleanup handlers. */ #include #include #include #include #include #include /* Defines the number of searching threads */ #define NUM_THREADS 5 /* Function prototypes */ void *search(void *); void print_it(void *); /* Global variables */ pthread_t threads[NUM_THREADS]; pthread_mutex_t lock; int tries; volatile int started; int libc_ex3() { int i; int pid; /* create a number to search for */ pid = getpid(); printf("Searching for the number = %d...\n", pid); /* Initialize the mutex lock */ pthread_mutex_init(&lock, NULL); /* Create the searching threads */ for (started=0; started