summaryrefslogtreecommitdiff
path: root/tests/reuse2.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-11-03 01:08:41 +0000
committerrpj <rpj>2004-11-03 01:08:41 +0000
commitec8290acdaea21b16d98f1ef5d4ae8a28ab2109a (patch)
tree0bd3750ec1cc12594b6cfe69473e393da6ec101b /tests/reuse2.c
parentcccaf0c2c82e78a72d69a4a50c872f308bed2f65 (diff)
Mutex, semaphore, thread ID, test suite changes - see ChangeLogs
Diffstat (limited to 'tests/reuse2.c')
-rw-r--r--tests/reuse2.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/tests/reuse2.c b/tests/reuse2.c
index 625611e..12aaa5f 100644
--- a/tests/reuse2.c
+++ b/tests/reuse2.c
@@ -53,7 +53,9 @@
* -
*
* Environment:
- * -
+ * - This test is implementation specific
+ * because it uses knowledge of internals that should be
+ * opaque to an application.
*
* Input:
* - None.
@@ -74,6 +76,9 @@
#include "test.h"
+/*
+ */
+
enum {
NUMTHREADS = 10000
};
@@ -95,11 +100,11 @@ main()
{
pthread_t t[NUMTHREADS];
pthread_attr_t attr;
- int i, j;
- int reuse,
- reuseMax = 0,
- reuseMin = NUMTHREADS,
- idTotal = 0;
+ int i;
+ unsigned int notUnique = 0,
+ totalHandles = 0,
+ reuseMax = 0,
+ reuseMin = NUMTHREADS;
assert(pthread_attr_init(&attr) == 0);
assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0);
@@ -120,43 +125,39 @@ main()
*/
for (i = 0; i < NUMTHREADS; i++)
{
- reuse = 0;
+ if (t[i].p != NULL)
+ {
+ unsigned int j, thisMax;
- if (t[i] == NULL)
- continue;
+ thisMax = t[i].x;
- for (j = 0; j < i; j++)
- {
- if (t[j] == t[i])
- {
- reuse++;
- t[j] = NULL;
- }
- }
- for (j = i + 1; j < NUMTHREADS; j++)
- {
- if (t[j] == t[i])
- {
- reuse++;
- t[j] = NULL;
- }
+ for (j = i+1; j < NUMTHREADS; j++)
+ if (t[i].p == t[j].p)
+ {
+ if (t[i].x == t[j].x)
+ notUnique++;
+ if (thisMax < t[j].x)
+ thisMax = t[j].x;
+ t[j].p = NULL;
+ }
+
+ if (reuseMin > thisMax)
+ reuseMin = thisMax;
+
+ if (reuseMax < thisMax)
+ reuseMax = thisMax;
}
- if (reuseMax < reuse)
- reuseMax = reuse;
- if (reuseMin > reuse)
- reuseMin = reuse;
}
for (i = 0; i < NUMTHREADS; i++)
- {
- if (t[i] != NULL)
- idTotal++;
- }
+ if (t[i].p != NULL)
+ totalHandles++;
printf("For %d total threads:\n", NUMTHREADS);
- printf("Reuse maximum = %d\n", reuseMax);
- printf("Reuse minimum = %d\n", reuseMin);
- printf("Total thread IDs allocated = %d\n", idTotal);
+ printf("Non-unique IDs = %d\n", notUnique);
+ printf("Reuse maximum = %d\n", reuseMax);
+ printf("Reuse minimum = %d\n", reuseMin);
+ printf("Total handles = %d\n", totalHandles);
return 0;
}