MCPcopy Create free account
hub / github.com/pydata/numexpr / th_worker

Function th_worker

numexpr3/module.cpp:35–161  ·  view source on GitHub ↗

Do the worker job for a certain thread

Source from the content-addressed store, hash-verified

33
34// Do the worker job for a certain thread
35void* th_worker(void *tidptr) {
36 int tid = *(int *)tidptr;
37 // Parameters for threads
38 npy_intp start;
39 npy_intp vlen;
40 npy_intp task_size;
41 NpyIter* iter;
42 NumExprObject* neObj;
43
44 int* pc_error;
45 int ret;
46 npy_intp istart, iend;
47 char** errorMessage;
48
49 while(1) {
50
51 if( tid == 0 ) {
52 gs.init_sentinels_done = 0; // sentinels have to be initialised yet
53 }
54
55 // Meeting point for all threads (wait for initialization)
56 CHECK_END_COND;
57 pthread_mutex_lock(&gs.count_threads_mutex);
58 if( gs.count_threads < gs.n_thread ) {
59 gs.count_threads++;
60 // printf( "Count threads start %d\n", gs.count_threads );
61 do {
62 pthread_cond_wait(&gs.count_threads_cv, &gs.count_threads_mutex);
63 } while (gs.barrier_passed == BARRIER_HALT);
64 }
65 else { // Every thread is ready, go...
66 gs.barrier_passed = BARRIER_PASS;
67 pthread_cond_broadcast(&gs.count_threads_cv);
68 }
69 pthread_mutex_unlock(&gs.count_threads_mutex);
70 // Get parameters for this thread before entering the main loop
71 start = gs.start;
72 vlen = gs.vlen;
73 task_size = gs.task_size;
74 neObj = &gs.params[tid];
75 pc_error = gs.pc_error;
76
77 errorMessage = gs.errorMessage;
78
79 // Loop over blocks
80 CHECK_END_COND;
81 pthread_mutex_lock(&gs.count_mutex);
82 if( !gs.init_sentinels_done ) {
83 // Set sentinels and other global variables
84 gs.gindex = start;
85 istart = gs.gindex;
86 iend = istart + task_size;
87 if (iend > vlen) {
88 iend = vlen;
89 }
90 gs.init_sentinels_done = 1; // sentinels have been initialised
91 gs.giveup = 0; // no giveup initially
92 } else {

Callers

nothing calls this directly

Calls 3

pthread_cond_waitFunction · 0.85
pthread_cond_broadcastFunction · 0.85
vm_engine_iter_taskFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…