2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers.
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 Dr. David Kirkby, e-mail drkirkby@ntlworld.com
26 /* This test program starts by puttting 10 into a 100x1000 array
27 then incrments it by 5 and decrements it by 2, one thousand
28 times. The incrment and decrement operations are prevented from
29 operlapping by a mutex variable. */
31 /* If we #define DISABLE_MUTEX, there is no locking
32 on the array and so any thread can overwrite at any time
33 so we would expect jibberish output */
45 #ifdef ENABLE_POSIX_THREADS
48 void *increment(void *y);
49 void *decrement(void *z);
55 pthread_mutex_t array_mutex;
57 int array[1000][1000];
59 #endif /* ifdef ENABLE_POSIX_THREADS */
63 #ifdef ENABLE_POSIX_THREADS
64 pthread_t thread1, thread2;
66 /* Put 10 in each array element */
71 pthread_mutex_init(&array_mutex, NULL);
72 #ifdef ENABLE_POSIX_THREADS
73 #ifdef HAVE_PTHREAD_SETCONCURRENCY
74 pthread_setconcurrency(6);
79 if( pthread_create(&thread1, NULL, increment, (void *) &r1) != 0)
81 perror("Thread 1 not created properly");
85 if( pthread_create(&thread2, NULL, decrement, (void *) &r2) != 0)
87 perror("Thread 2 not created properly");
91 if(pthread_join(thread1, NULL) != 0)
93 perror("Thread 1 did not join properly");
96 if(pthread_join(thread2, NULL) != 0)
98 perror("Thread 2 did not join properly");
102 ret=check_array(); /* Returns 0 or 1 */
110 #ifdef ENABLE_POSIX_THREADS
111 void *increment(void *pnum_times)
114 if( pthread_mutex_lock(&array_mutex) != 0)
116 perror("pthread_mutex_lock failed");
119 /* Increment each value in the array by 5, so
120 we can check the values later. */
121 for(i=0; i<1000; ++i)
122 for(j=0; j<1000; ++j)
124 if( pthread_mutex_unlock(&array_mutex) != 0)
126 perror("pthread_mutex_unlock failed");
133 void *decrement(void *pnum_times)
138 #ifndef DISABLE_MUTEX
139 if( pthread_mutex_lock(&array_mutex) != 0)
141 perror("pthread_mutex_lock failed");
146 /* Decrement each value in the array by 2, so
147 we can check the values later. */
148 for(i=0; i<1000; ++i)
149 for(j=0; j<1000; ++j)
152 #ifndef DISABLE_MUTEX
153 if(pthread_mutex_unlock(&array_mutex) != 0)
155 perror("pthread_mutex_unlock failed");
165 for(i=0; i<1000; ++i)
167 for(j=0; j<1000; ++j)
169 /* Numers start at 10, but get incremented by
170 5 by 2, which is 3 . Loop runs 2000 times,
171 so resuls should be 2000*(5-2) + 10 = 6010 */
173 if (array[i][j] != 310)
175 fprintf(stderr,"array[%d][%d]=%d\n",i,j,array[i][j]);