pthreads

C user space library modifying jmp_buf doesnt make my function go to the correct address

Im trying to modify a jmp_buf so it executes a function (after i setjmp and longjmp back in). I have a struct called t that stores information about each thread. start_routine is a function pointer that should be executed. /* this is inside an init() function setting stuff up */ void init(void *(*start_routine)(void*), void *arg) { ...

Segmentation fault when catching exceptions in a libpthread linked app ( linux, C++ )

Hi I have this piece of code here: These are functions used to create and stop a pthread: void WatchdogController::conscious_process_handler_start() { if ( debug ) cout << "WatchdogController: starting conscious process thread" << endl; cn_pr_thread_active = true; if ( pthread_create( &cn_pr_thread, NULL, conscious_proc...

Basics Question: Best Practices concerning Posix Threads and Dynamic Memory

Is it advisable or even possible to have a dynamically growing array of structs fed and read by different concurrently running posix threads? Where do I have to look for best practices for applications of that sort - are there any which are "common wisdom"? I am new to this area and would need some initial pointers for where to start and...

undefined reference to pthread_create in linux (c programming)

I'm interested in learning to write C programs which use threads. I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/ #include <pthread.h> #include <stdio.h> #define NUM_THREADS 5 void *PrintHello(void *threadid) { long tid; tid = (long)threadid; printf("Hello World! It's me, thre...

Posix threads problem

Hello, I am trying to understand pthreads by example. I have made the following code that is giving different answers everytime I run! Could anyone explain the bug please? TIA, Sviiya The code is here: #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 4 struct thread_data { int thread_id; ...

pthreads: inconsistency between gcc and icc on Linux

Hello, The following code produces wrong and inconsistent output with gcc (4.1.2 20080704) but correct and expected output with icc (Version 11.1) . But when I moved the thread_data_array[] definition from main() to global (immediately after the struct thread_data definition) it works fine with both compilers. I do not see why this chang...

Can a pthread perform clean-up on its own?

Let's say I: malloc a pthread_tfor holding a thread context pthread_create with as user parameter the pointer to the pthread_t structure In other words, the thread function has access to its pthread_t context structure. Now here is the tricky bit: How can the pthread exit on its own and get the pthread_t context freed somehow? i.e. ...

Does exiting from a pthread release malloced memory ?

Let's say I pthread_create and then pthread_detach it. Now, from within the thread function, I malloc some block. When the thread exits, will the malloc'ed memory be freed automatically? (been googling for an answer to no avail...) ...

Mac OS X port crashes in pthread_setspecific in glibstdc++ vsnprintf - how to troubleshoot?

I'm testing a Mac OS X port of my multithreaded server. It starts up, but it dies in vsnprintf soon after the first client request is taken by a worker thread. It seems that vsnprintf is trying to manipulate some thread local memory with pthread_setspecific. This dereferences a bad pointer. Then, gdb traps a dlopen call, gets an error,...

How do I determine if a pthread is alive?

How do I determine if a detached pthread is still alive ? I have a communication channel with the thread (a uni-directional queue pointing outwards from the thread) but what happens if the thread dies without a gasp? Should I resign myself to using process signals or can I probe for thread liveliness somehow? ...

Implementing a Priority queue with a Conditional Variable in C

My current understanding of conditional variables is that all blocked (waiting) threads are inserted into a basic FIFO queue, the first item of which is awakened when signal() is called. Is there any way to modify this queue (or create a new structure) to perform as a priority queue instead? I've been thinking about it for a while, but...

Multiple threads in C program

I'm writing a Unix application in C which uses multiple threads of control. I'm having a problem with the main function terminating before the thread it has spawned have a change to finish their work. How do I prevent this from happening. I suspect I need to use the pthread_join primitive, but I'm not sure how. Thanks! ...

weird error when passing pthread_t to function

I have a C header file which defines the following function: void my_func(pthread_t tid); This is defined by another function: void my_func(pthread_t tid) { ... When I compile, it says: ****.h:2: error: expected specifier-qualifier-list before ‘pthread_t’ Any ideas what I'm doing wrong? ...

autoconf with -pthread

Greetings. I am trying to create an autoconf configure script that automatically checks for which pthread option to use and, ideally, specifies -pthread when compiling with gcc. It was my hope that AX_PTHREAD would work, but neither seems to work on MacOS 10.6. I'm using AX_PTHREAD from http://www.nongnu.org/autoconf-archive/ax%5Fpthre...

uniprocessor or multiprocessor

On unix, how could we know whether the system is multiprocessor or uniprocessor? ...

how to increase the priority of a child pthread relative to the parent thread

My application creates a helper pthread that I need to have run at a higher priority than the main thread. I tried to set the priority of the created thread like this: struct sched_param param; pthread_attr_t tattr; pthread_attr_init(&tattr); pthread_attr_getschedparam(&tattr, &param); param.sched_priority = sched_get_priority_max(SCHE...

core dump in a multithread program

Hi, i was trying to write a simple multithreaded program. It is dumping the core. I have my function that is called when a thread is created below: void *BusyWork(void *t) { int i; int *tid; int result=0; tid = t; printf("Thread %d starting...\n",*tid); for (i=0; i<10; i++) { result = result + (i* i); } ...

query about a multithreading program

this might a simple query. when we are creating a thread we are passing the (void *)t as an argument to a function PrintHello.we are copying the value in the pointer threadid(typacasting it to long) in tid which is a long variable again.i am confused with the parameter passing. is this a pass by reference or pass by value.over all is t...

How do I start to use multithread programming?

I am a beginner on Stack Overflow. I am working on a Unix platform in C/C++. Knowing basic programming in these regards how could I start with multithreading? Multithreading seems to be very interesting and I want to grow my knowledge in this regard. How could I get started with multithreading and what are the best techniques/books/ebo...

c library function to get number of active threads

Hi everybody, I'm developing a multi threaded Unix application in C. Is there a simple way to get the count of the number of simultaneously active threads? I don't want to have to write the code to keep track of the number of active thread if it already can be done for me by the library! :-) I'm using POSIX pthreads, and I'm trying to ...