h_cancel.c revision 274575
190075Sobrien/* $NetBSD: h_cancel.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $ */
2169689Skan
3146895Skan/*
490075Sobrien * Copyright (c) 2008 The NetBSD Foundation, Inc.
590075Sobrien * All rights reserved.
690075Sobrien *
7132718Skan * Redistribution and use in source and binary forms, with or without
890075Sobrien * modification, are permitted provided that the following conditions
9132718Skan * are met:
10132718Skan * 1. Redistributions of source code must retain the above copyright
11132718Skan *    notice, this list of conditions and the following disclaimer.
12132718Skan * 2. Redistributions in binary form must reproduce the above copyright
1390075Sobrien *    notice, this list of conditions and the following disclaimer in the
14132718Skan *    documentation and/or other materials provided with the distribution.
15132718Skan *
16132718Skan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17132718Skan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1890075Sobrien * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19132718Skan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20132718Skan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21169689Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22169689Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2390075Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2490075Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2590075Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2690075Sobrien * POSSIBILITY OF SUCH DAMAGE.
27132718Skan */
28132718Skan
29132718Skan#include <sys/cdefs.h>
30169689Skan__COPYRIGHT("@(#) Copyright (c) 2008\
31132718Skan The NetBSD Foundation, inc. All rights reserved.");
32132718Skan__RCSID("$NetBSD: h_cancel.c,v 1.1 2010/07/16 15:42:53 jmmv Exp $");
33132718Skan
34132718Skan#include <stdio.h>
35132718Skan#include <stdlib.h>
36132718Skan#include <pthread.h>
37169689Skan#include <unistd.h>
38169689Skan
39169689Skanint
40169689Skanmain(void)
41169689Skan{
42169689Skan	char str1[] = "You should see this.\n";
43169689Skan	char str2[] = "You should not see this.\n";
4490075Sobrien
4590075Sobrien#ifdef __NetBSD__
46132718Skan	printf("Cancellation test: Self-cancellation and disabling.\n");
47132718Skan#endif
4890075Sobrien
4990075Sobrien	pthread_cancel(pthread_self());
50169689Skan
51132718Skan	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
52132718Skan
53169689Skan	write(STDOUT_FILENO, str1, sizeof(str1)-1);
54169689Skan
55169689Skan	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
56169689Skan
57132718Skan	write(STDOUT_FILENO, str2, sizeof(str2)-1);
58132718Skan
59169689Skan	exit(1);
60169689Skan}
61132718Skan