Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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.

Filter by
Sorted by
Tagged with
3 votes
1 answer
89 views

Multithread execution times are slow on Ubuntu and fast on Windows

I'm working on a project accelerating the execution of a Genetic Algorithm both on multiple cores and on a GPU. The algorithm is specifically suited for the solution of the Traveling Salesman Problem ...
Pietro Pianigiani's user avatar
2 votes
3 answers
92 views

Simple rwlock implementation in C

Can someone please review my rwlock implementation to see if there are any issues with correctness (hopefully not), give any feedback on how to write good C code etc, design patterns which could be ...
Tejas Anand's user avatar
2 votes
2 answers
214 views

Circular Queue Producer Consumer with Mutex and Condition Variable vs. Sempahore

How can I optimize the performance of the code below? Destruction of the condition variable at the end of main blocks, not sure why this behavior is occurring. Is it possible to remove some of the ...
Darnoc Eloc's user avatar
1 vote
0 answers
81 views

binary semaphores implementation pthread

Can someone see if have not made some stupid mistakes in the binary semaphore implementation? I know that some more checks have to be added but I have eventually lost the initial idea in the details. <...
0___________'s user avatar
2 votes
2 answers
144 views

Wait for child while polling file descriptor with self-pipe controlled by different threads

I am working on a personal project, and one of the things it does is to call a blocking operation on a file descriptor while a forked+exec'ed child process is running. It needs to know when the ...
Seninha's user avatar
  • 171
4 votes
3 answers
391 views

Implementation of pthread multithreading and mutex

I am trying to implement a "proper" pthread multithreading program with pthread mutex. I want it to be as C-standard-conforming and POSIX-conforming as possible. The below is my ...
D.J. Elkind's user avatar
7 votes
2 answers
3k views

Proper implementation of signal handler and multithreading (pthread)

I am trying to implement a "proper" signal handler that works correctly for multiple threads, and to be as C-standard-conforming and POSIX-conforming as possible. The below is my ...
D.J. Elkind's user avatar
8 votes
2 answers
897 views

Event functionality in C

I am beginner to intermediate and wanted to write a little event code in c. It's one header file with 108 line pure code and it does what I was thinking it should be like for me. EventListener.h ...
mortytheshorty's user avatar
1 vote
2 answers
153 views

semaphore barriers exercise os three easy pieces

I am reading the book OS three easy pieces, In the semaphore chapter I am going through barrier.c question. Below is the code that needs to be completed for the desired output: ...
Hackaholic's user avatar
15 votes
2 answers
1k views

A multithreaded implementation of the 'which' command

Here is an implementation of the 'which' command which can tell where programs are located. ...
JohnScott's user avatar
  • 171
6 votes
3 answers
923 views

A priority based timer using priority queue

I am trying to implement a priority-based timer where certain events are fired out based on their expiry and the priority. So if there are 3 timers with the following expiry time and priorities ...
xyf's user avatar
  • 508
4 votes
1 answer
812 views

A tiny threads pool in C

I'm a newbie in C, and currently following Stanford CS107 - Programming Paradigms. For assignment 6, I find it'd be better to isolate the threads management from the service logic. The following code ...
weiShen's user avatar
  • 205
3 votes
1 answer
343 views

Time slice for thread check

A code to check the time slice for each thread separately, it will receive an integer number from the command line for the number of threads to run simultaneously. Would love some feedback on what is ...
SA.93's user avatar
  • 123
4 votes
2 answers
340 views

Thread Synchronization - CPU Usage exceeds 200 - C program

I have a working program that reads user input keys and echoes them back to the screen using the producer/consumer paradigm (the project requires you to use threads). While this program does work, it ...
user232489's user avatar
3 votes
2 answers
304 views

Implementing metropolis algorithm in C

This is my second C program (an improved version of the first one). I want to optimize this simulation. Algorithm The simulation algorithm is: The system can go from \$i\$ to \$i+1\$ with probability ...
Kartik Chhajed's user avatar
3 votes
0 answers
83 views

Async generation of large buffers of random numbers on the GPU

I would like to obtain some feedback on a simple code I wrote to implement an easy and hopefully fast way to generate a large number of floats with CURAND and use them one at a time. This is achieved ...
rng_help's user avatar
1 vote
0 answers
264 views

Simple header-only thread and mutex for both windows and linux in C

I wanted to get some thread support on windows with very simple headers for a library that I'm working on but it had to work on both Windows and Linux. Since C11 threads are not widely supported, this ...
LeoVen's user avatar
  • 337
2 votes
1 answer
776 views

Shared counter variable among different threads

I have a need to use a shared variable among different threads in c/C++. So putting my knowledge of threads and mutexes I have written the below sample code. Can anyone please review the code and ...
Vijay's user avatar
  • 129
2 votes
1 answer
926 views

Thread Pool in C for web server

Please review the following code for thread pool in C (I wrote it to implement a threaded web server for my personal project). I have been programming in C++ and Java but never did any serious ...
Anmol Gautam's user avatar
6 votes
1 answer
2k views

C++ simple inter-process notification system

I needed to synchronise several processes, so I developed this ipn::Notifier class that uses a mutex+condition variable stored in shared memory to notify all ...
José Tomás Tocino's user avatar
4 votes
1 answer
903 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 ...
Nikko77's user avatar
  • 137
12 votes
1 answer
3k views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
Jon Nimrod's user avatar
2 votes
1 answer
731 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 ...
Richard Robinson's user avatar
3 votes
1 answer
297 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 ...
Kubie's user avatar
  • 131
2 votes
1 answer
2k 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 ...
Sam Hammamy's user avatar
5 votes
1 answer
3k 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 ...
Incomputable's user avatar
  • 9,484
6 votes
1 answer
3k 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 ...
Bernardo Meurer's user avatar
3 votes
1 answer
2k views

Multithreaded matrix multiplication on Unix in C

I have this program for comparing serial and parallel matrix multiplication algorithms: matrix.h ...
coderodde's user avatar
  • 28.5k
2 votes
0 answers
1k 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? ...
coderodde's user avatar
  • 28.5k
9 votes
1 answer
1k 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,...
Subhranil's user avatar
  • 191
5 votes
1 answer
762 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 ...
doplumi's user avatar
  • 263
10 votes
1 answer
299 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 ...
Tob Ernack's user avatar
5 votes
1 answer
170 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 ...
coderodde's user avatar
  • 28.5k
7 votes
2 answers
925 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 ...
coderodde's user avatar
  • 28.5k
4 votes
4 answers
11k 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 ...
Berkin's user avatar
  • 141
4 votes
3 answers
1k 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 ...
user2635088's user avatar
5 votes
2 answers
626 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. ...
bw0248's user avatar
  • 233
1 vote
1 answer
900 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 ...
dbmitch's user avatar
  • 295
4 votes
1 answer
2k 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 ...
pinetreepatzer's user avatar
5 votes
4 answers
22k 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 (...
Sri Church's user avatar
-2 votes
1 answer
3k 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" ...
Vishnu N K's user avatar
1 vote
2 answers
242 views

Pascal's triangle with libgmp and pthread in C

I have written a program to generate a pascal triangle of predefined size. Code ...
theoden8's user avatar
  • 329
8 votes
1 answer
96 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 ...
Nick's user avatar
  • 83
10 votes
2 answers
3k 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: <...
Joao Ferreira's user avatar
5 votes
5 answers
2k 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 ...
Patrick's user avatar
  • 369
3 votes
1 answer
2k 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 ...
OiciTrap's user avatar
  • 133
1 vote
1 answer
3k 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 ...
BM-'s user avatar
  • 161
2 votes
1 answer
1k 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.... ...
Becca Bohem's user avatar
0 votes
1 answer
102 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: ...
LastSecondsToLive's user avatar
4 votes
1 answer
1k 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'...
Dallas's user avatar
  • 43