Mercurial > mxe-octave
annotate src/pthreads-test.c @ 4037:85abb6c3ec8b
of-netcdf: patch for --enable-64 (Bug #46060)
* src/of-netcdf-1-fixes.patch: new file
* dist-files.mk: add of-netcdf-1-fixes.patch
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Tue, 29 Sep 2015 19:43:19 -0400 |
parents | 99516e73b368 |
children |
rev | line source |
---|---|
2351
8a6c466753e2
Improve comment style of all test programs
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
1 /* |
8a6c466753e2
Improve comment style of all test programs
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
2 * This file is part of MXE. |
2353
99516e73b368
Move doc/index.html -> index.html
Volker Grabsch <vog@notjusthosting.com>
parents:
2351
diff
changeset
|
3 * See index.html for further information. |
2351
8a6c466753e2
Improve comment style of all test programs
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
4 */ |
982
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
5 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
6 #include <stdio.h> |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
7 #include <pthread.h> |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
8 |
988
e55bb62b2970
improved test programs of packages libgomp and pthreads
Volker Grabsch <vog@notjusthosting.com>
parents:
982
diff
changeset
|
9 #define N 4 |
982
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
10 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
11 void *thread_fn(void *p) |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
12 { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
13 const int *arg = p; |
988
e55bb62b2970
improved test programs of packages libgomp and pthreads
Volker Grabsch <vog@notjusthosting.com>
parents:
982
diff
changeset
|
14 fprintf(stderr, "Hello from thread %d, nthreads %d\n", *arg, N); |
982
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
15 return NULL; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
16 } |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
17 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
18 int main(int argc, char *argv[]) |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
19 { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
20 pthread_t threads[N]; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
21 int args[N]; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
22 int i; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
23 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
24 (void)argc; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
25 (void)argv; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
26 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
27 for (i = 0; i < N; i++) { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
28 args[i] = i; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
29 if (pthread_create(threads + i, NULL, thread_fn, args + i) != 0) { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
30 return 1; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
31 } |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
32 } |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
33 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
34 for (i = 0; i < N; i++) { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
35 if (pthread_join(threads[i], NULL) != 0) { |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
36 return 2; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
37 } |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
38 } |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
39 |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
40 return 0; |
4d2e6c7c2cc2
test program for package pthreads (by Martin Lambers)
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
41 } |