pthreads

Is it legitimate to pass an argument as void*?

I have just started learning pthreads API and I am following the tutorial here However, in an example program of pthread_create, the sample program creates a long variable and passes its value, typecasted as void*. In the thread entry function, it dereferences it just like a long. Is this legit? I understand if I pass the address of v...

global static boolean pointer causes segmentation fault using pthread

New to pthread programming, and stuck on this error when working on a C++&C mixed code. What I have done is to call the c code in the thread created by the c++ code. There is a static boolean pointer is_center used in the thread and should got free when the thread finishes. However I noticed that every time when the program processed...

Multiple Socket Connections

I need to write a server which accepts connections from multiple client machines, maintains track of connected clients and sends individual clients data as necessary. Sometimes, all clients may be contacted at once with the same message, other times, it may be one individual client or a group of clients. Since I need confirmation that t...

Multitasking how to make worker thread gain control after calling infinite loop function

assume creating 3 worker threads by pthread_create, in these worker thread routine, each call a simple infinite loop function which do not have a return to do counting how to make worker thread gain control after calling infinite loop function and save the context of infinite loop function for calling in worker thread again? ...

how to clear stack after stack overflow signal occur

In pthread, After reaching yellow zone in stack, signal handler stop the recursive function by making it return however, we can only continue to use extra area in yellow zone, how to clear the rubbish before the yellow zone in the thread stack ? (Copied from "answers"): #include <pthread.h> #include <stdio.h> #include <stdlib.h> ...

Can't get any speedup from parallelizing Quicksort using Pthreads

I'm using Pthreads to create a new tread for each partition after the list is split into the right and left halves (less than and greater than the pivot). I do this recursively until I reach the maximum number of allowed threads. When I use printfs to follow what goes on in the program, I clearly see that each thread is doing its delega...

linux pthread_suspend

Looks like linux doesnt implement pthread_suspend and continue, but I really need em. I have tried cond_wait, but it is too slow. The work being threaded mostly executes in 50us but occasionally executes upwards of 500ms. The problem with cond_wait is two-fold. The mutex locking is taking comparable times to the micro second executi...

C: Fifo between threads, writing and reading strings

Hello once more dear internet, I writing a small program that among other things, writes a log file of commands received. to do that, I want to use a thread that all it should do is just attempt to read from a pipe, while the main thread will write into that pipe whenever it should. Since i don't know the length of each string command, ...

Marshalling a C structure to C#

Hi, I don't know how to marshall this structure in Mono. typedef struct rib_struct { rib_used_t used; rib_status_t status; rib_role_t role; uint8_t conf; rib_dc_t *pending; pthread_mutex_t mutex; pthread_cond_t cond; rib_f_t *props; } rib_t; And for example, rib_dc_t is like: typedef struct rib_dc_stru...

What time function do I need to use with pthread_cond_timedwait?

The pthread_cond_timedwait function needs an absolute time in a time timespec structure. What time function I'm suppose to use to obtain the absolute time. I saw a lot of example on the web and I found almost all time function used. (ftime, clock, gettimeofday, clock_gettime (with all possible CLOCK_...). The pthread_cond_timedwait use...

How to safely operate on parameters in threads, using C++ & Pthreads?

Hi. I'm having some trouble with a program using pthreads, where occassional crashes occur, that could be related to how the threads operate on data So I have some basic questions about how to program using threads, and memory layout: Assume that a public class function performs some operations on some strings, and returns the result ...

Thread toggling

Hi all, In Ubuntu, I am running 2 'C' applications, When I press key up/down the applications are alternatively getting the events. What might be the problem/solution? Ex: I have 'A application' and 'B application', I launch 'A application' and press the key up/down its working fine. If I simultaneously launch 'B application' and focu...

Permanent mutex locking causing deadlock?

I am having a problem with mutexes (pthread_mutex on Linux) where if a thread locks a mutex right again after unlocking it, another thread is not very successful getting a lock. I've attached test code where one mutex is created, along with two threads that in an endless loop lock the mutex, sleep for a while and unlock it again. The ou...

Linux synchronization with FIFO waiting queue

Are there locks in Linux where the waiting queue is FIFO? This seems like such an obvious thing, and yet I just discovered that pthread mutexes aren't FIFO, and semaphores apparently aren't FIFO either (I'm working on kernel 2.4 (homework))... Does Linux have a lock with FIFO waiting queue, or is there an easy way to make one with exis...

how to emulate thread local storage at user space in C++ ?

I am working on a mobile platform over Nucleus RTOS. It uses Nucleus Threading system but it doesn't have support for explicit thread local storage i.e, TlsAlloc, TlsSetValue, TlsGetValue, TlsFree APIs. The platform doesn't have user space pthreads as well. I found that __thread storage modifier is present in most of the C++ compilers. ...

Problem with pthreads mutex and condition variables

Hi, The problem I am seeking some help for is written in point no. 7. Before that, I describe the structure of my code. From main(), two threads thread1 and thread2 are created and initialized to two functions fun1() and fun2() respectively. I have a mutex named lock_mutex and condition variables named cond1, cond2, cond3 and cond4. I ...

One thread reading and another writing to volatile variable - thread-safe?

In C I have a pointer that is declared volatile and initialized null. void* volatile pvoid; Thread 1 is occasionally reading the pointer value to check if it is non-null. Thread 1 will not set the value of the pointer. Thread 2 will set the value of a pointer just once. I believe I can get away without using a mutex or condition ...

virtual memory consumption of pthreads

Hello I developed a multi-threaded TCP server application that allows 10 concurrent connections receives continuous requests from them, after some processing requests, responds them to clients. I'm running it on a TI OMAP l137 processor based board it runs Monta Vista Linux. Threads are created per client ie 10 threads and it's pre-thre...

My app mem usage is growing using pthread.

Hi, I am using C language and Linux as my programming platform. In my user-space application. I used pthread to create a thread. int main() { pthread_t thread1, thread2; pthread_create( &thread1, NULL, fthread1, NULL ); pthread_create( &thread2, NULL, fthread2, NULL ); return 0; } void *fthread1( void *ptr ) { /* do s...

One producer, Two consumers and usage of pthread_cond_signal & pthread_mutex_lock

I am fairly new to pthread programming and am trying to get my head around cond_signal & mutex_lock. I am writing a sample program which has One producer thread and Two consumer threads. There is a queue between producer and the first consumer and a different queue between producer and the second consumer. My producer is basically a co...