/*
* Copyright (c) 2003-2005 Hewlett-Packard Development Company, L.P.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
printf("Testing %s\n", name);
if (nthreads > MAX_NTHREADS)
{
fprintf(stderr, "run_parallel: requested too many threads\n");
abort();
}
# ifdef _HPUX_SOURCE
/* Default stack size is too small, especially with the 64 bit ABI */
/* Increase it. */
if (pthread_default_stacksize_np(1024*1024, 0) != 0)
{
fprintf(stderr, "pthread_default_stacksize_np failed. "
"OK after first call.\n");
}
# endif
pthread_attr_init(&attr);
for (i = 0; i < nthreads; ++i)
{
int code = pthread_create(thr + i, &attr, f1, (void *)(long)i);
if (code != 0)
{
fprintf(stderr, "pthread_create returned %d, thread %d\n", code, i);
abort();
}
}
for (i = 0; i < nthreads; ++i)
{
int code = pthread_join(thr[i], NULL);
if (code != 0)
{
fprintf(stderr, "pthread_join returned %d, thread %d\n", code, i);
abort();
}
}
if (t())
{
printf("Succeeded\n");
}
else
{
fprintf(stderr, "Failed\n");
abort();
}
return 0;
}
#endif /* USE_PTHREADS */
#ifdef USE_VXTHREADS
void * run_parallel(int nthreads, thr_func f1, test_func t, const char *name)
{
int thr[MAX_NTHREADS];
int i;
printf("Testing %s\n", name);
if (nthreads > MAX_NTHREADS)
{
fprintf(stderr, "run_parallel: requested too many threads\n");
taskSuspend(0);
}
for (i = 0; i < nthreads; ++i)
{
thr[i] = taskSpawn((char*) name, 180, 0, 32768, (FUNCPTR) f1, i,
1, 2, 3, 4, 5, 6, 7, 8, 9);
if (thr[i] == ERROR)
{
fprintf(stderr, "taskSpawn failed with %d, thread %d\n",
errno, i);
taskSuspend(0);
}
}
for (i = 0; i < nthreads; ++i)
{
while (taskIdVerify(thr[i]) == OK)
taskDelay(60);
}
if (t())
{
printf("Succeeded\n");
}
else
{
fprintf(stderr, "Failed\n");
taskSuspend(0);
}
return 0;
}
#endif /* USE_VXTHREADS */