blob: d29f2fc5f22c1b5daa00898a9b3bcc9e3b27aadb [file] [log] [blame]
Russ Cox6c976392013-02-20 17:48:23 -05001// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Aram Hăvărneanu2230e9d2015-03-30 23:11:36 +02005// +build darwin dragonfly freebsd linux netbsd openbsd solaris
Russ Cox6c976392013-02-20 17:48:23 -05006
7#include <pthread.h>
8#include "_cgo_export.h"
9
10static void*
11addThread(void *p)
12{
13 int i, max;
14
15 max = *(int*)p;
16 for(i=0; i<max; i++)
17 Add(i);
18 return 0;
19}
20
21void
22doAdd(int max, int nthread)
23{
24 enum { MaxThread = 20 };
25 int i;
26 pthread_t thread_id[MaxThread];
27
28 if(nthread > MaxThread)
29 nthread = MaxThread;
30 for(i=0; i<nthread; i++)
31 pthread_create(&thread_id[i], 0, addThread, &max);
32 for(i=0; i<nthread; i++)
33 pthread_join(thread_id[i], 0);
34}