1231990Smp/* This testcase is part of GDB, the GNU debugger. 259243Sobrien 359243Sobrien Copyright 2002-2020 Free Software Foundation, Inc. 459243Sobrien 559243Sobrien This program is free software; you can redistribute it and/or modify 659243Sobrien it under the terms of the GNU General Public License as published by 759243Sobrien the Free Software Foundation; either version 3 of the License, or 859243Sobrien (at your option) any later version. 959243Sobrien 1059243Sobrien This program is distributed in the hope that it will be useful, 1159243Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1259243Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1359243Sobrien GNU General Public License for more details. 1459243Sobrien 1559243Sobrien You should have received a copy of the GNU General Public License 1659243Sobrien along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1759243Sobrien 1859243Sobrien#include <unistd.h> 1959243Sobrien#include <stdlib.h> 2059243Sobrien#include <pthread.h> 2159243Sobrien 22167465Smpvoid *thread_function(void *arg); /* Pointer to function executed by each thread */ 23167465Smp 24167465Smp#define NUM 1 2559243Sobrien 26167465Smpunsigned int args[NUM+1]; 27167465Smp 2859243Sobrienint main() { 2959243Sobrien int res; 3059243Sobrien pthread_t threads[NUM]; 3159243Sobrien void *thread_result; 3259243Sobrien long i; 3359243Sobrien 3459243Sobrien for (i = 1; i <= NUM; i++) 3559243Sobrien { 3659243Sobrien args[i] = 1; 37167465Smp res = pthread_create(&threads[i - 1], 3859243Sobrien NULL, 3959243Sobrien thread_function, 4059243Sobrien (void *) i); 4159243Sobrien } 4259243Sobrien 4359243Sobrien /* schedlock.exp: last thread start. */ 4459243Sobrien args[0] = 1; 4559243Sobrien thread_function ((void *) 0); 4659243Sobrien 4759243Sobrien exit(EXIT_SUCCESS); 4859243Sobrien} 4959243Sobrien 5059243Sobrienvoid *thread_function(void *arg) { 51167465Smp int my_number = (long) arg; 5259243Sobrien int *myp = (int *) &args[my_number]; 5359243Sobrien 5459243Sobrien /* Don't run forever. Run just short of it :) */ 5559243Sobrien while (*myp > 0) 5659243Sobrien { 5759243Sobrien (*myp) ++; /* insert breakpoint here */ 58167465Smp } 5959243Sobrien 60167465Smp pthread_exit(NULL); 6159243Sobrien} 6259243Sobrien