When trying to implement a simple echo server with concurrent support on linux. Following approaches are used: Use pthread functions to create a pool of thread, and maintained in a linked list. It’s created on process start, and destroy on process termination. Main thread will accept request, and use a POSIX message queue to store accepted socket file descriptor. Threads
Tag: pthreads
C – pthread_self() getting truncated first 4 bytes?
I’m having trouble getting pthread_equal() to match stored pthreads. The pthread_t I get from pthread_self() seems to be truncated by 4 bytes compared to the one I get from pthread_create(). Comparisons are in the last code block! As a result, an attempt to loop through the stored pthreads and compare with pthread_equals fail. Some comparisons (all ten, every time, get
Segmentation fault with ucontext makecontext on OS X 10.10
I run my code in OS X 10.10 with gcc. I am trying to implement a usercontext library. If I comment out thread_create( &t2, thr2, NULL);, the code will produce desired effect. I have no idea why a line related to t2 will lead to segmentation fault of t1. Author’s Notes I happily work on implementing a usercontext library after
Any equivalent function to pthread_getcpuclockid since i have tid of Thread
To get perf statistics of parallel running threads – To get list of threads I use thread list in /proc/self/task Now I want to get ID of a thread’s CPU time clock. But clock_getcpuclockid only works with PIDs. pthread_getcpuclockid requires the pthread id of thread and I did not find any way to get pthread id from TId of thread
SEGFAULT after recv from socket
I have next trouble: after receiving data from sockets, server app generates segfault and shutdown. Code of client and server side are below. server: Client: In other words, client connected successfully. But after sending message, server generate segm fault error. What went wrong? Answer When running the code it seg faults at: Package is a struct with two members nick
Does Java JVM use pthread?
Does JVM on Mac OS X use pthread to create threads? What about on Linux distributions, is it now default way to create threads for JVM on all distributions? Answer Yes, HotSpot JVM (i.e. Oracle JDK and OpenJDK) uses pthreads on Linux and on Mac OS X.
Why does linking with pthread cause a segmentation fault?
I have a stripped down simple program with a static variable (‘abc.cpp’): I compile it and it works: However, if I link in the pthread library…. I know it doesn’t use threading here, but in the actual non-stripped-down program, it links to a library that does use threading. It feels like it should be okay to link to pthread even
how to implement POSIX threads ( pthread.h ) on fedora 9
I need to use pthreads but it seems that I do not have it in my fedora and I cannot found how to install it. Thanks Answer Fedora 9 uses Linux Kernel version 2.6 and this version is fully compatible with libc 2.3.2. This libc contains the pthread.h header. Check this implementation example. And compile with:
pthread_mutex_t in multiple processes…who destroys it?
I’m using a pthread_mutex_t to synchronize access to a resource between multiple processes which are on the same level (i.e. there isn’t a parent/child relationship). How can I determine when it’s safe to call pthread_mutex_destroy? The only way I can think of to determine if the mutex is in use by another process without introducing a race condition is to
Which thread handles the signal?
I have 2 threads(thread1 and thread2). And I have signal disposition for SIGINT. Whenever SIGINT occurs thread 2 should handle the signal. For that I wrote below program I compiled and and run the program. for every 1 second “thread1 active” is printing and for every 3 seconds “thread2 active” is printing. Now I generated SIGINT. But its printing “thread1