Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pthreads]

Pthreads (POSIX Threads) is a standardised C-based API for creating and manipulating threads on a POSIX-compliant system. It is defined by the standard "POSIX.1c, Threads extensions (IEEE Std 1003.1c-1995)", and subsequently by the Single Unix Specification.

4
votes
1answer
71 views

C++ Simple Game Beeping Utility

Lately I have been playing a game called Dirty Bomb. I like it very much, and since I was taking a rest of basic C++ OpenGL, i tried to make a simple console utility for it. What i wanted to achieve ...
9
votes
1answer
127 views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
2
votes
1answer
62 views

Simple multithreading C project

I'm fairly new to C, and this is my first time using pthread. I am pretty sure I implemented it correctly, however I'd like to verify it is indeed executing the ...
2
votes
1answer
108 views

A* search on 4x4 sliding tile puzzle scales poorly

I am trying to improve the time complexity of my A* search algorithm and I have tried approaching this from every which way I believe is possible. I believe I may be doing something fundamentally ...
2
votes
1answer
134 views

A send and receive UDP node in C

I am working on a (personal) light weight distributed project for the Rpi platform. Making it distributed requires P2P communication between the nodes, and I thought it would be a good time to learn ...
5
votes
1answer
687 views

Simplified std::thread implementation using pthreads

Background I'm taking Operating Systems class this semester, and I was allowed to C++, but not std::thread or any other facilities that are present in the linux ...
3
votes
0answers
548 views

A Thread-Safe FIFO in C99

I started a little weekend project to try and learn how to multithread with pure C99 and POSIX threads. The project is composed of three threads, input, processing, and output, which communicate with ...
3
votes
1answer
797 views

Multithreaded matrix multiplication on Unix in C

I have this program for comparing serial and parallel matrix multiplication algorithms: matrix.h ...
2
votes
0answers
536 views

Thread-safe rand for C

I have this very short program for dealing with thread-safety of C's rand. Is it a correct implementation? ...
8
votes
1answer
270 views

Dynamically extensible threadpool implementation in C

Purpose For my recent project, I needed a thread pool. I saw a lot of implementations at GitHub, but most of them were quite complicated. With complication comes performance penalty. Most importantly,...
5
votes
1answer
347 views

Exercise – Synchronization between threads using `pthread_mutex_t` and `pthread_cond_t`

I have got an assignment for an OS course that consists in the use of mutex and condition variables to synchronize N threads, each involved in the search of a character in a row of a NxN matrix. The ...
10
votes
1answer
199 views

Lightweight asynchronous event library in C - Threadpool module

I have finished writing a C library whose purpose is to provide a simple API for asynchronously executing functions, waiting for events on file descriptors and waiting for timeouts. The whole library ...
5
votes
1answer
112 views

Concurrent stack in C - follow-up

This is a follow-up question to Concurrent stack in C The pop function not just removes the top element from the stack, but also returns it. If a pthreads call ...
7
votes
2answers
363 views

Concurrent stack in C

(See also the follow-up question.) I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements: the stack has maximum ...
4
votes
4answers
5k views

Socket client in C using threads

I'm working on socket programming in C. I have no problem with usage the threads. This all works fine but I'm new in this area. I wrote this code in client.c but is there any misused code or something ...
3
votes
2answers
229 views

Simple mutex and conditional variable signal in C

I'm new to multithreading in C so I made a toy program that uses a mutex and a conditional variable to communicate between two threads. do_work performs a task ...
5
votes
2answers
401 views

Dining Philosophers variation in C

This is a variation of the Dining Philosophers Problem. The task is to coordinate several students inside a gym. All students try to obtain their desired training weights from a shared weight rack. ...
1
vote
1answer
446 views

Reading socket stream to parse XML, queue messages, run system cmd in thread

I've had great experience in the past getting feedback from uDev and python, but I'm dreading this attempt at C++. I have a little background in C - but absolutely none in C++ - so this code is ...
4
votes
1answer
562 views

Simple file server for GET requests

I recently made this simple server in C for Linux systems and was wanting to get another set of eyes on it for a review of the design. I am new to socket programming and used a textbook from school to ...
4
votes
4answers
15k views

Multithreaded Client/ Server communication

This is my first network programming codes writing for a client who has the following requirement: My Server has to run 24*7*365 for multiple clients at the same time (concurrency). Their Client (...
-2
votes
1answer
2k views

Printing infinite loop using pthread [closed]

I'm trying to implement a c program using pthreads which prints "1 2 3 4 5" in an infinite loop. I have used conditional variables and mutex to synchronize the pthreads. I'm able to print "1 2 3 4 5" ...
1
vote
2answers
129 views

Pascal's triangle with libgmp and pthread in C

I have written a program to generate a pascal triangle of predefined size. Code ...
8
votes
1answer
75 views

Automated Safety System Daemon in C89

Explanation This software is currently designed to: Spawn a daemon which controls and monitors multiple threads Create threads based on a 'list' of functions Monitor threads for operation Restart ...
10
votes
2answers
2k views

Thread to send heartbeat UDP packets

This C code will run on an embedded machine with a Linux OS. It should create data packets (ASCII) to repeatedly be sent to a UDP server. Just to give an overview about what functions should do: <...
5
votes
2answers
825 views

Thread synchronization with mutex

This program prints odd numbers by thread1 and even numbers by thread2 sequentially. Can this code be optimized or made more ...
3
votes
1answer
906 views

Simple pool of threads which calculate the sum of a given number from the main process

I have to make a program which creates a number of threads that are waiting at the beginning, then the main process creates a doubly linked list where random numbers are put and then a signal tells ...
1
vote
1answer
2k views

Multithreaded MJPG network stream server

I'm a bit of a neophyte when it comes to C++, and so I'd like some feedback regarding a recent project. The code sits on a Raspberry Pi and streams camera data over TCP on a specified port. The ...
1
vote
1answer
185 views

Using semaphore in C

This is my first time using semaphores and I was wondering if I implemented them to the best of their abilities in my code.... ...
0
votes
1answer
56 views

Loading message with Pthreads

I want to print a nice loading message with these three fading dots, while the main thread does some heavy IO stuff. This is why I implemented this: ...
4
votes
1answer
549 views

Multiplying square matrix with C pthreads (POSIX threads)

I'm a student, and I'm trying to make the product of two square matrix with some threads in the soup. I've already worked on some fast single-threaded product (with some cache-friendly tricks), and I'...
3
votes
1answer
110 views

Thread sync using conditional variables

Can you review the code? ...
3
votes
1answer
138 views

Async safe threadpool

I'm trying the write a threadpool that can safely be added inside a signal handler or in code forked by multithreaded code. Are there any corner cases that would cause this code to fail? What could be ...
0
votes
1answer
245 views

Multiple producers accessing multiple shared queues by checking for space two times

I request a review on the way multiple producers and consumers access multiple shared queues. What I have done here requires the threads to check for the space in queues minimum two times. Can it be ...
2
votes
0answers
68 views

N Processing connect to a single process: Socket Programming

The idea of my program is to use pthreads, semaphores, posix shared memory, and sockets to create an environment where N processes (that we will refer to as the children) can connect to a single ...
4
votes
2answers
985 views

pthread_cond_wait() based multithreaded Linux daemon skeleton

I'm trying to design a multithreaded daemon for an industrial automation related project. The daemon will be using a number of 3rd party libs like MQTT, mysql, etc.. My idea is to have worker threads ...
5
votes
1answer
2k views

Using a mutex to read from a file [closed]

I am new to C and I am trying to implement a mutex. The idea of the program is: main() will create three threads. Each thread will read one character each from ...
5
votes
1answer
2k views

Porting Java's synchronized() block to C++

I tried to create a class for porting Java's synchronized keyword to C++ using below code using *nix pthread's library. In general my test cases seem to work, but since this is a very critical topic ...
4
votes
2answers
2k views

Implementing pthread barrier for Mac OS/X

I have written this little thingie to fix a problem of missing pthread_barrier_t in Mac OS/X pthreads. Are there any issues with this code? The header: ...
2
votes
1answer
4k views

Readers-Writers problem in C

I would love some suggestions on this code of mine, pointers on overall design, code quality, optimization in terms of memory and speed. ...
7
votes
2answers
1k views

Harmonic partial sum calculator with multithreading

I wrote a program which computes the harmonic partial sum to N terms with multithreading capability. I've been working on this to sharpen my C++ skills for the upcoming semester. Just wondering if ...
5
votes
3answers
139 views

Counting letters as quickly as possible

I received a task, of taking a known text file (Linux dictionary), use threads to count the different letters in it, and present the results in an array. The code doesn't have to be pretty, elegant, ...
4
votes
1answer
483 views

Vehicle-crossing simulation

It seems like this code should be shorter, but with all the error checking it is long and hard to follow. This is for a simulation of vehicles crossing a bridge, and this part is dealing with mutexes. ...
4
votes
2answers
2k views

Example of a Multithreaded C program

In answering password cracker in c with multithreading, I ended up writing a sample in C, which is not my forte. Is there anything that I missed which should have been included in a responsible ...
4
votes
1answer
123 views

Synchronous events library

I have implemented a small library that handles synchronous events with POSIX compliant threads. I oriented me on the already existing POSIX thread API. Here are the files I created: ...
3
votes
1answer
1k views

Consumer producer implementation involving POSIX, semaphores, and locks

I am trying to get over my fear of multithreading programming and teaching myself to code using POSIX. I wrote a small version of the consumer producer problem. I am hoping I can get some feedback if ...
5
votes
1answer
7k views

Consumer-Producer Problem: POSIX Thread

I have implemented a producer consumer problem, following the resources below: Oracle doc CSEE I have used mutex_t and sem_t. ...
7
votes
1answer
4k views

Scalability of C server implementation based on pthreads

I am wondering about the feasibility of the following basic implementation of a server and how well it would scale. I know that large-scale, distributed servers should probably be written in a ...
19
votes
1answer
21k views

Thread-safe concurrent FIFO queue in C++

Is this the correct way to implement a thread-safe concurrent FIFO queue in C++? It requires passing unsigned char* arrays of binary data. Thread Safe Concurrent ...
2
votes
1answer
217 views

1 Producer, N Consumers working in parallel, each doing ~1/nth of a task

I am not wondering about error checking (I will add that soon). I would instead like to know about correctness, efficiency and simplicity. ...
8
votes
3answers
25k views

Dining philosophers problem with mutexes

I know this dining philosophers problem has been researched a lot and there are resources everywhere. But I wrote simple code to solve this problem with C and then turned to the Internet to see if it'...