Questions tagged [pthreads]

Pthreads (POSIX Threads) is a standardised C-based API for creating and manipulating threads. It is currently defined by POSIX.1-2008 (IEEE Std 1003.1, 2013 Edition / The Open Group Base Specifications Issue 7).

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

threadpool funtion cant release function

i am using the threadpool lib from https://github.com/Pithikos/C-Thread-Pool here is my code #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #...
Neverwin's user avatar
0 votes
3 answers
64 views

Function that can execute every other function

I'm studying threads in university and I would like to make a library in C that does similar things to pthread but using processes and then compare the performances of both. In other words I would ...
Emanuele Falanga's user avatar
0 votes
0 answers
20 views

iOS Swift Stuck When Using A Static pthread_rwlock in Release Build but Debug Build Works Fine

I'm using Xcode15 and targeting iOS 17. The freeze happens on the Manager.setValue(key:value:) call within the init method of the StaticRwlockApp struct. This issue does not occur when I run the app ...
yfkyqdk's user avatar
0 votes
1 answer
87 views

How to make sure thread has copied resource before detach?

I need create a new thread using pthread_create, which will detach later. The new thread will need to copy some content over, which will go out of scope after detached. Below is an example. My ...
auzn's user avatar
  • 613
0 votes
1 answer
33 views

Signal Handling In Pthread

in signal header there was a signal and raise. Signal is used to capture the signal and the raise is used to sending signal to the caller parameter. But in multithread programming that used the ...
Apabila X Terkadang's user avatar
0 votes
1 answer
46 views

Pthread Specific Data In Linux System

In the Linux System we can use pthread for multithread programming and in the pthread there was a pthread specific data where we should first create a key. But what is the purpose of pthread specific ...
Apabila X Terkadang's user avatar
1 vote
1 answer
68 views

wrong usage of pthread_create?

I am trying to understand if my approach may result in undefined behavior. I have allocated 10 elements of my structure using calloc in this manner: struct myStructure { int index; int myNum; ...
dsfddg dggd's user avatar
0 votes
0 answers
52 views

Linux thread key

Below the code example : #include <iostream> #include <pthread.h> pthread_key_t key; int value_10 = 10; int value_20 = 20; int value = 20; using namespace std; voidthreadFunction1(void ...
Darevil294's user avatar
1 vote
2 answers
77 views

Thread Detach In Linux System

what I know is that detach( ) makes the main function not to wait until all threads have finished. #include <unistd.h> #include <iostream> #include <pthread.h> using namespace std; ...
onxy tzy's user avatar
0 votes
1 answer
57 views

Segmentation fault using pthreads and sscanf in C

I am getting a segmentation fault due to the first sscanf statement in the transaction method. I am unsure why this is occurring. I have tried to change the sscanf statement and variables but that did ...
Danial Mithani's user avatar
1 vote
1 answer
76 views

c threads don't print correctly

I'm trynig to implement a simple program in C with some threads. In details, i want that each thread read only a part of a CSV file (that contain only four float numbers per row) and put the read ...
Giorgio Aveni's user avatar
0 votes
1 answer
83 views

Implementing WaitForSingleObject(GetCurrentThread(),INFINITE) in Linux

I want to know why pthread_join(pthread_self(),NULL) leads to undefined behaviour, but WaitForSingleObject(GetCurrentThread(),INFINITE) is fine? Also, if I want to replace WaitForSingleObject(...
Piyush Kumar Gupta's user avatar
0 votes
0 answers
46 views

What does segmentation fault mean in this context? [duplicate]

I am working on a program that schedules a number of non-interactive jobs in the background based on a number given by the user. Afterwards, the user is meant to use keywords such as "submit"...
Florence's user avatar
0 votes
1 answer
57 views

Conflict with pthreads and mutex lock

I'm trying to do the following assignment: You will write a program that creates three threads. These threads access a shared integer, buffer, one at a time. The buffer will initially be set to 0. ...
Pablo's user avatar
  • 13
1 vote
0 answers
48 views

Increasing the number of threads makes the program slower

I'm currently trying to implement a linked list with multithreading access to it by using read-write locks. Though it does seem to work correctly I've been trying to see what was the performance ...
Luca Mautino's user avatar
0 votes
0 answers
111 views

After what instruction the thread migrates to another logical processor?

I want to know at what point in the program execution flow (more exactly, after what instruction), the thread migrates from logical processor 0 to logical processor 1. I use SetProcessAffinityMask() ...
Kudor's user avatar
  • 49
-1 votes
0 answers
35 views

How to receive information from thread to main thread and then give information back / C language, pthreads, mutex

The number of threads should be specified by #define NUM_THREADS number Program version using mutex or semaphore Write a program in which each thread generates two random numbers. Then the main ...
JaChceTylkoZdacStudia's user avatar
0 votes
1 answer
14 views

How to use Multi Pthread

Hi I have a question about pthreads I am repeatedly testing pthread_create and pthread_join, but it seems that the argument values passed to the function are not being passed properly However, if I ...
김태정's user avatar
0 votes
0 answers
35 views

Unable to find pthread.h for mingw32 on nix

I'm trying to cross-compile a program which uses pthreads to windows using nix and mingw. The build complains about missing headers (pthread.h), even though i set windows.pthreads as a buildInput. ...
MaxSilvester's user avatar
1 vote
0 answers
54 views

implementing matrix addition in c

I'm currently learning how to implementing threads and matrix in c right now and having trouble implementing a function that performs matrix addition with two threads. The code below if the function ...
dev jonston's user avatar
0 votes
0 answers
21 views

performant python code, for the combination of 10 digit numbers

I would like to know if this code, see below, can be accelerated. I'm not sure but could the library "thread" help, or something similar? Can this task be split up so that it is completed in ...
Lisa_sh's user avatar
  • 41
0 votes
0 answers
22 views

Is it still possible to set thread affinity in macOS?

mach_port_t thread_port = pthread_mach_thread_np(pthread_self()); thread_affinity_policy_data_t policyData1; policyData1.affinity_tag = 1; int b = 0; kern_return_t t1 = thread_policy_set(thread_port, ...
benrush's user avatar
  • 45
1 vote
1 answer
41 views

What makes a pthread the "main" thread?

What makes a pthread the "main thread"? I'm asking because some GLFW functions must only be called from the main thread. I understand the concept of thread safety. But what is special about ...
hanno's user avatar
  • 6,431
0 votes
1 answer
50 views

Sometimes my binary semaphore does not wait the correct time

Sometimes it does not wait long enough. I probably missed something simple - but I cant find it. Why from time to time wait function is returning prematurely #define SEMAPHORE_MAXWAIT -1 #define ...
0___________'s user avatar
1 vote
0 answers
54 views

how to deliberately cause deadlock in test cases to guard concurrent bug steadily?

Imagine I have a complex test case which can cause two threads deadlock occasionally. It's not suiteable, I think, to run in CI for guarding concurrent bugs. I want to write a simple test case to ...
Lewis Chan's user avatar
0 votes
0 answers
51 views

Need to divide the password cracking system according to the amount of threads that is entered by the user in the command prompt argv[1]

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <crypt.h> #include <unistd.h> #include <pthread.h> int count = 0; // A counter used to track ...
simanta's user avatar
2 votes
1 answer
100 views

Is there a way to reduce the heap size of threads in C language? [closed]

massif diagram I used Valgrind's Massif feature to check the memory usage of my C language program to investigate memory usage. I had many dynamic allocations in my code, but according to Massif, I ...
Kay's user avatar
  • 23
1 vote
1 answer
63 views

How could I synchronize multiple threads with only the use of pthread mutexes?

I was trying to make three threads that each open a different input file, read a single character from it and set it to a global variable and then wait for the next thread to read a single character ...
brocoli's user avatar
  • 33
0 votes
1 answer
53 views

pthread_setschedparam not working on GCC with mingw64

I'm trying to run the example code from here on Windows 11 with GCC v13.2.0 installed (MSYS2, UCRT runtime): #include <chrono> #include <cstring> #include <iostream> #include <...
Mark's user avatar
  • 1
-4 votes
1 answer
68 views

Is sem_timedwait defined if the time to wait is 0 [duplicate]

Is sem_timedwait defined if the time to wait is 0 or should I call sem_trywait in this condition? Documentation is unclear and source code shows only the implementation. I want to know if Posix ...
0___________'s user avatar
0 votes
0 answers
14 views

two unique_lock a same mutex performs differently with/without compile option -pthread

Source code in main.cpp: #include <iostream> #include <mutex> #include <thread> int main() { std::mutex mtx; std::cout << "Start" << std::endl; ...
Jie Feng's user avatar
0 votes
1 answer
40 views

pthread gets cancelled before releasing locks

I am still very new to multi-threading in C. I have written a simple program that does the following: The main function starts a number of threads, each waiting for flag start to be set using a ...
Florin Zamfir's user avatar
1 vote
1 answer
117 views

Why is an instruction being sometimes executed twice when using threads C

I have the following code which basically creates two threads, one reads a character, and the other one types it untill the letter f is passed : char c; int att = 1; void* th_read(void *k){ ...
Rafik Bouloudene's user avatar
0 votes
1 answer
50 views

dbus-cxx Block main thread until DBUS connection is disconnected

I'm using the dbus-cxx library to communicate between programs using DBUS. However, one part I'm confused about is how to keep the main thread from exiting while the connection is open on the server ...
nreh's user avatar
  • 466
1 vote
1 answer
74 views

Sending SIGTERM Signal to Only the Current Thread in Rust

use nix::sys::signal::{self, SigSet}; #[tokio::test] async fn test_shutdown() { let server = TestServer::new().await; let proxy = ProxyUnderTest::new(server.listen_port).await; sleep(std::time::...
Vinay Sawant's user avatar
1 vote
1 answer
89 views

Semaphore not initialised properly with sem_open

I am trying to implement the producer and consumer problem with semaphores. I think I got the logic correct but my code isn't working as expected. #include <stdio.h> #include <pthread.h> ...
Ku-hello's user avatar
1 vote
3 answers
116 views

Forcing `pthread_create` to fail for test purposes

In order to test error recovery, I want to make pthread_create fail in a predictable manner. The most obvious way to do that is to put a hard upper limit on the number of threads that are allowed to ...
zwol's user avatar
  • 137k
0 votes
1 answer
87 views

how to make timer_create and timer_delete multi-thread proof

I am stuck in a peculiar situation where I call timer_create from one thread and call the timer_delete from another thread. But I cant seem to get it work as it ends up in a deadlock: I cannot figure ...
newww's user avatar
  • 69
0 votes
0 answers
27 views

Xenomai IPC buffers between realtime and non realtime threads

I've got a realtime application using Xenomai with the Alchemy skin, which has to communicate between the realtime and non realtime threads. To do this I've created some buffers using rt_buffer_create(...
user22629504's user avatar
0 votes
1 answer
34 views

Why does a joinable thread terminate before pthread_join?

The documentation for the pthread_join function says: Failure to join with a thread that is joinable (i.e., one that is not detached), produces a "zombie thread". As far as I understand ...
helhel's user avatar
  • 5
0 votes
1 answer
19 views

Why can't we get the thread termination code from the detached thread?

My question is strange, but that's what it is. My question: Is there any explanation why the posix threads developers did not make it possible to get the exit code from a detached thread? I understand ...
helhel's user avatar
  • 5
0 votes
1 answer
58 views

how to effeciently use Pthread to generate and process combinations with multiple threads?

I have 2 files, 1 containing all 16-bit numbers and another containing 144 custom 8-bit numbers. My goal is to generate combination is like this [16-bit][16-bit][8-bit], a total of 40 bits then since ...
diviserbyzero's user avatar
-1 votes
1 answer
70 views

What should be the output of this multithreaded code (pthreads - c)?

#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<pthread.h> #define max_thread 5 int d = 0; pthread_t thread_id[max_thread]; //the thread function definition ...
Aryaman Gupta's user avatar
1 vote
2 answers
51 views

Calling `accept` syscall in loop creates corrupted sockets

I'm trying to build myself a web app in C. So far, I've got the HTTP server working, but for some reason, when I have things like HTML files that require other CSS, and JavaScript files, the browser (...
Nexuss's user avatar
  • 57
0 votes
1 answer
52 views

passing multiple arguments to pthread (including vector arguments)

I currently have a problem related with the use of pthread.h (since I am still pretty new at it) so I am really hopeful I could get some help from this forum..let's suppose I want to pass this ...
DeadlyKitten999's user avatar
0 votes
0 answers
62 views

Reason for serial linked list implementation takes more time than a linked list implementation with mutex using one thread?

To investigate the performance gain using more threads I used a linked list implementation and did a number of random operations serially and using threads with mutex. My linked list functions are in ...
Mohamed Ishad's user avatar
0 votes
0 answers
15 views

Unit testing using ceedling

i could not generate the coverage results of the source files. error is Could not find coverage results for src/thr_func1.c Could not find coverage results for src/thr_func2.c Could not find coverage ...
Ragul's user avatar
  • 1
1 vote
1 answer
48 views

CMAKE Linux Mint building gtest "/usr/bin/ld: cannot find -lThreads::Threads: No such file or directory"

CMAKE Linux Mint building gtest /usr/bin/ld: cannot find -lThreads::Threads: No such file or directory This is Gtest Out of the box after apt-get install libgtest-dev works PERFECT on a slightly ...
npcmplete's user avatar
1 vote
1 answer
87 views

(GNU+Linux) Multiple threads calling malloc() at the same time

I read online that most moden UNIX systems come with a thread-safe malloc() by default. I know this simply means that a thread can call malloc() safely while another thread is already in the middle of ...
Kevin Stefanov's user avatar
0 votes
1 answer
54 views

Is there a way to prevent a descendant thread from getting into cgroup of its ancestor thread automatically?

I write some threads of my app to a Linux cpu cgroup, created by me, explicitly (let us talk e.g. about v1 for now, but if you know a way for v2, that would be also great). However, I see that ...
JenyaKh's user avatar
  • 2,080

1
2 3 4 5
179