From 5ec5415402ee6e4ae21e4a50c04360908325ba81 Mon Sep 17 00:00:00 2001 From: Mark Whitley Date: Mon, 12 Mar 2001 20:00:00 +0000 Subject: Program for testing concurrent access to syslogd. --- tests/tst-syslogd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/tst-syslogd.c (limited to 'tests/tst-syslogd.c') diff --git a/tests/tst-syslogd.c b/tests/tst-syslogd.c new file mode 100644 index 000000000..bae10afdf --- /dev/null +++ b/tests/tst-syslogd.c @@ -0,0 +1,44 @@ +/* + * tst-syslogd.c - tests concurrent threads calling syslog + * + * build with: gcc -Wall tst-syslogd.c -lpthread + */ + +#include +#include +#include +#include + +void *log_func(void *arg) +{ + int i; + int thrid = (int)arg; + + openlog(NULL, LOG_PERROR | LOG_PID, LOG_USER); + for (i = 0; i < 10; i++) { + syslog(LOG_DEBUG, "thread %i iter %i\n", thrid, i); + sleep(thrid); /* this mixes things up a bit */ + } + closelog(); + + return NULL; +} + +int main(int argc, char **argv) +{ + pthread_t thr1, thr2, thr3; + int id1 = 1; + int id2 = 2; + int id3 = 3; + + pthread_create(&thr1, NULL, log_func, (void *)id1); + pthread_create(&thr2, NULL, log_func, (void *)id2); + pthread_create(&thr3, NULL, log_func, (void *)id3); + + pthread_join(thr1, NULL); + pthread_join(thr2, NULL); + pthread_join(thr3, NULL); + + return 0; +} + -- cgit v1.2.3