Re: [capi-sig] capi-sig Digest, Vol 35, Issue 4

June 5, 2010
5:05 a.m.
sorry about the attachment
On 06/05/2010 06:00 PM, capi-sig-request@python.org wrote:
#include <Python.h> #include <pthread.h> #include <time.h> #include <stdio.h>
typedef struct _thrdStruct { int num; pthread_t self; } thrdStruct;
void* thrdFunc( void *p ) { thrdStruct *thrd = ( thrdStruct* ) p; thrd->self = pthread_self(); //PyGILState_STATE gstate = PyGILState_Ensure();
printf( "THRD %d\n", thrd->num);
//Py_BEGIN_ALLOW_THREADS
sleep(15);
//Py_END_ALLOW_THREADS
//PyGILState_Release(gstate);
return NULL;
}
int main( int argc, char *argv[] ) { thrdStruct thrds[10]; pthread_t self[10] = {0}; int rv, i; void *stat; PyGILState_STATE gstate;
Py_Initialize();
PyEval_InitThreads();
gstate = PyGILState_Ensure();
for (i=0;i<10;i++) {
thrds[i].num = i;
rv = PyThread_start_new_thread( thrdFunc, &thrds[i] );
//rv = pthread_create( &self[i], NULL, thrdFunc,
&thrds[i] ); } PyGILState_Release(gstate);
//Py_BEGIN_ALLOW_THREADS
sleep(1);
//Py_END_ALLOW_THREADS
for (i=0;i<10;i++) {
if ( self[i] != thrds[i].self )
printf( "%d %x %x\n", i, self[i], thrds[i].self);
}
for (i=0;i<10;i++) {
rv = pthread_join( thrds[i].self, &stat );
}
Py_Finalize();
}
5396
Age (days ago)
5396
Last active (days ago)
0 comments
1 participants
participants (1)
-
Shaun Savage