2 Copyright (C) 2004-2005 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <sys/types.h>
36 void* ThreadHandler(void* arg
)
39 printf("ThreadHandler\n");
42 read(fFifo
, &c
, sizeof(c
));
44 //pthread_testcancel();
46 } catch (std::exception e
) {}
50 int main(int argc
, char * const argv
[])
56 printf("Thread test\n");
57 std::set_terminate(__gnu_cxx::__verbose_terminate_handler
);
59 sprintf(fName
, "/tmp/fifo");
61 if (stat(fName
, &statbuf
)) {
62 if (errno
== ENOENT
) {
63 if (mkfifo(fName
, 0666) < 0) {
64 printf("Cannot create inter-client FIFO [%s]\n", fName
);
68 printf("Cannot check on FIFO %s\n", fName
);
72 if (!S_ISFIFO(statbuf
.st_mode
)) {
73 printf("FIFO (%s) already exists, but is not a FIFO!\n", fName
);
78 if ((fFifo
= open(fName
, O_RDWR
|O_CREAT
, 0666)) < 0) {
79 printf("Cannot open fifo [%s]", fName
);
83 if (res
= pthread_create(&fThread
, 0, ThreadHandler
, NULL
)) {
84 printf("Cannot set create thread %d\n", res
);
89 printf("Cancel Thread\n");
90 pthread_cancel(fThread
);
91 pthread_join(fThread
, &status
);