Path: blob/main/lib/libc/tests/stdlib/dynthr_mod/dynthr_mod.c
39553 views
/*1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 2019 Andrew Gierth4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*26* Though this file is initially distributed under the 2-clause BSD license,27* the author grants permission for its redistribution under alternative28* licenses as set forth at <https://rhodiumtoad.github.io/RELICENSE.txt>.29* This paragraph and the RELICENSE.txt file are not part of the license and30* may be omitted in redistributions.31*/3233#include <stdio.h>34#include <stdlib.h>35#include <stdarg.h>36#include <string.h>37#include <unistd.h>38#include <pthread.h>3940void mod_main(int op);4142static pthread_t thr;4344static void *45mod_thread(void *ptr __unused)46{47char *volatile dummy;4849dummy = malloc(500);50*dummy = 'a';51return (NULL);52}5354void55mod_main(int op)56{57int rc;5859switch (op) {60case 1:61rc = pthread_create(&thr, NULL, mod_thread, NULL);62if (rc != 0)63_exit(1);64break;65case 0:66pthread_join(thr, NULL);67break;68}69}70717273