Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120632627
ptwrapper.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 5, 18:58
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Jul 7, 18:58 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27212038
Attached To
R2795 mitgcm_lac_leman_abirani
ptwrapper.c
View Options
/*
* $Header: /u/gcmpack/MITgcm/eesupp/src/ptwrapper.c,v 1.1 2004/08/29 17:13:24 edhill Exp $
* $Name: $
*
*
* A PTHREADS convenience wrapper intended primarily for use with
* gcc/g77 which does not support an "automatic" (here, meant as a
* compiler-supported) threading mechanism.
*
*/
#ifdef HAVE_PTHREADS
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <pthread.h>
void ptreentry_(int* myThid);
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int num_threads = 0;
void *
threadfunc(void *parm)
{
int myThid;
int rc;
rc = pthread_mutex_lock(&mutex);
num_threads++;
myThid = num_threads;
rc = pthread_mutex_unlock(&mutex);
ptreentry_(&myThid);
}
void
ptinit_(int* nthreads)
{
int i,j;
int rc;
pthread_t threadids[10];
pthread_attr_t pta;
pthread_attr_init(&pta);
pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE);
/* start the threads */
for (i=0; i<(*nthreads); i++)
rc = pthread_create(&threadids[i], &pta, threadfunc, NULL);
/* wait on thread termination */
for (i=0; i<(*nthreads); i++)
rc = pthread_join(threadids[i], NULL);
}
#endif /* HAVE_PTHREADS */
Event Timeline
Log In to Comment