[1329] | 1 | /* $Id: threadsignals.c 1329 2004-03-23 00:17:37Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * Experiment with sending other threads exceptions.
|
---|
| 5 | *
|
---|
| 6 | * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
| 7 | *
|
---|
| 8 | *
|
---|
| 9 | * This file is part of InnoTek LIBC.
|
---|
| 10 | *
|
---|
| 11 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU Lesser General Public License as published
|
---|
| 13 | * by the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU Lesser General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU Lesser General Public License
|
---|
| 22 | * along with InnoTek LIBC; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 24 | *
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #define INCL_BASE
|
---|
| 30 | #include <os2.h>
|
---|
| 31 | #include <stdio.h>
|
---|
| 32 | #include <process.h>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | ULONG _System exceptionhandler(PEXCEPTIONREPORTRECORD pXRepRec,
|
---|
| 36 | struct _EXCEPTIONREGISTRATIONRECORD *pXRegRec,
|
---|
| 37 | PCONTEXTRECORD pCtx, PVOID pv)
|
---|
| 38 | {
|
---|
| 39 | printf("exception: %#lx info[0]=%#lx\n", pXRepRec->ExceptionNum, pXRepRec->ExceptionInfo[0]);
|
---|
| 40 | return XCPT_CONTINUE_SEARCH;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void threadproc(void *arg)
|
---|
| 44 | {
|
---|
| 45 | ULONG rc;
|
---|
| 46 | EXCEPTIONREGISTRATIONRECORD XRegRec;
|
---|
| 47 |
|
---|
| 48 | XRegRec.ExceptionHandler = exceptionhandler;
|
---|
| 49 | XRegRec.prev_structure = (PVOID)-1;
|
---|
| 50 | DosSetExceptionHandler(&XRegRec);
|
---|
| 51 |
|
---|
| 52 | rc = DosSleep(~0);
|
---|
| 53 | printf("DosSleep returned rc=%lu\n", rc);
|
---|
| 54 |
|
---|
| 55 | DosUnsetExceptionHandler(&XRegRec);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | int main()
|
---|
| 60 | {
|
---|
| 61 | TID tid;
|
---|
| 62 | ULONG rc;
|
---|
| 63 | tid = _beginthread(threadproc, NULL, 0x10000, NULL);
|
---|
| 64 | printf("started thread %ld\n", tid);
|
---|
| 65 | DosSleep(100);
|
---|
| 66 | rc = DosKillThread(tid);
|
---|
| 67 | printf("DosKillThread returned %lu\n", rc);
|
---|
| 68 | return 0;
|
---|
| 69 | }
|
---|