static buffer_t b;
-static void producer(int* id)
+static void *producer(void* arg)
{
+ int* id = arg;
+
buffer_send(&b, id);
- pthread_exit(NULL);
+ return NULL;
}
#define MAXSLEEP (100 * 1000)
-static void consumer(int* id)
+static void *consumer(void* arg)
{
+ int* id = arg;
int d;
+
usleep(rand() % MAXSLEEP);
buffer_recv(&b, &d);
if (! quiet)
printf("%i: %i\n", *id, d);
fflush(stdout);
}
- pthread_exit(NULL);
+ return NULL;
}
#define THREADS (10)
for (i = 0; i < THREADS; ++i)
{
thread_arg[i] = i;
- pthread_create(producers + i, NULL,
- (void * (*)(void *)) producer, &thread_arg[i]);
+ pthread_create(producers + i, NULL, producer, &thread_arg[i]);
}
for (i = 0; i < THREADS; ++i)
- pthread_create(consumers + i, NULL,
- (void * (*)(void *)) consumer, &thread_arg[i]);
+ pthread_create(consumers + i, NULL, consumer, &thread_arg[i]);
for (i = 0; i < THREADS; ++i)
{
* submatrix p->a[0..p->rows-1,0..p->rows-1] is the identity matrix.
* @see http://en.wikipedia.org/wiki/Gauss-Jordan_elimination
*/
-static void gj_threadfunc(struct gj_threadinfo* p)
+static void *gj_threadfunc(void *arg)
{
+ struct gj_threadinfo* p = arg;
int i, j, k;
elem_t* const a = p->a;
const int rows = p->rows;
}
}
}
+ return NULL;
}
/** Multithreaded Gauss-Jordan algorithm. */
t[i].cols = cols;
t[i].r0 = i * rows / s_nthread;
t[i].r1 = (i+1) * rows / s_nthread;
- pthread_create(&t[i].tid, &attr, (void*(*)(void*))gj_threadfunc, &t[i]);
+ pthread_create(&t[i].tid, &attr, gj_threadfunc, &t[i]);
}
pthread_attr_destroy(&attr);
// Function definitions.
-static void thread_func(struct cthread* thread_info)
+static void *thread_func(void *arg)
{
+ struct cthread* thread_info = arg;
int i;
pthread_mutex_lock(&s_mutex);
}
pthread_mutex_unlock(&s_mutex);
+
+ return NULL;
}
int main(int argc, char** argv)
cthread_ctr(p);
p->m_threadnum = p - thread_vec;
p->m_sema = &sema;
- pthread_create(&p->m_thread, 0,
- (void*(*)(void*))thread_func, &*p);
+ pthread_create(&p->m_thread, 0, thread_func, &*p);
}
for (i = 0; i < s_signal_count; i++)
{