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
0answers
19 views

libgnuutils memory leak when threading

I'm doing some threading and I've been getting this memory leak. The threads run through then join at the end. I'm new to threading so I don't really know what the library error is shown by Valgrind ...
0
votes
0answers
16 views

How to create multithreaded HTTP client in C for the following server code [on hold]

I am unable to make my HTTP client as multi-threaded. The code for the multi-threaded HTTP server is below. Kindly share the right way to execute the code below: https://github.com/ozgurhepsag/Multi-...
1
vote
1answer
48 views

fork() duplicates process, how about threads?

I am figuring out how threads with fork work and here is the code that I have tried to make some sense of. (Pardon the errors in the code) #include <stdio.h> #include <pthread.h> #include ...
1
vote
1answer
28 views

Concurrency using POSIX

I came across a passage: The definition of concurrent execution in POSIX requires that "functions that suspend the execution of the calling thread shall not cause the execution of the other threads ...
0
votes
1answer
16 views

passing an ofstream object to a thread function via pthread_create

I want to pass an ofstream object to a thread using pthread_create function. Let's say I create an object like this in my main(int argc, char *argv[]) function. ofstream file1(argv[1], fstream::out|...
0
votes
1answer
49 views

Multi threading error segmentation fault in C

I am trying to multiply two matrices using multi threading. Here I compile the program using gcc in linux and run by inputting number of threads. gcc multiThread.c -o test -lpthread ./test 4 Here I ...
0
votes
0answers
11 views

Why am I getting a Sysmalloc Error when using pthread?

I am getting an error that says "malloc.c: 2399: sysmalloc: Assertion`(....) failed". I can't find a solution to this problem. I am trying to create a thread to calculate the dot product of two ...
2
votes
1answer
54 views

Multithreaded Fibonacci Pair Program

I'm trying to write a program which creates two threads: a "front-end" and "back-end" thread. I want to create a "back-end" thread to iterate and compute pairs of terms from the fibonacci sequence and ...
1
vote
0answers
26 views

GCC: --whole-archive recipe for static linking to pthread stopped working in recent gcc versions

Static linking against pthread is a difficult topic on Linux. It used to work to wrap -lpthread as -Wl,--whole-archive -lpthread -Wl,--no-whole-archive (the details can be found in this answer). The ...
-1
votes
1answer
34 views

Calculate a value and update this in a GUI python, without block my gui

I have a simple application, one label and 2 buttons ( start increment, stop increment), write in pyqt5. When I pres start button want to see in ui, value update in real time and have acces at stop ...
1
vote
2answers
40 views

Spawning Arbitrary Number of Threads

I'm trying to write a program which will spawn an arbitrary number of threads, similar to the code I have in Convert a process based program into a thread based version?, which uses processes to do ...
-2
votes
1answer
41 views

Convert a process based program into a thread based version?

I currently have this program which spawns an arbitrary number of child processes and I'm interested in having it implement threads instead of processes. I'm having trouble understanding how to ...
0
votes
1answer
31 views

A while infinte cycle actually stops using threads

I'm new to C and I am trying to learn. I'm trying to implement multithreading in my program, but I'm having problems. The program (and the threads) should be going on running in a infinite loop, but ...
0
votes
1answer
19 views

What is the relationship between pthread priority and pthread policy?

I'm currently learning pthreads and am struggling to understand the relationship between thread priority and policy. What I know so far: The thread priority is an integer that indicates priority. The ...
0
votes
0answers
39 views

Post all schedule task at once in laravel

I have list of scheduled post in database on a particular time. And am using crontab to call that function and execute all using foreach loop. My problem is let's say i have 10 posts at same time by ...
0
votes
1answer
43 views

Pthread: Increasing program execution time with respect to number of threads

I am trying to build an efficient concurrent hash map using pthreads, C. Following is my implementation #include <stdlib.h> #include <stddef.h> #include <pthread.h> #include <...
2
votes
1answer
42 views

How do I secure that all threads created in a function return before the very same function terminates?

Consider the following section of a C function: for (int i = 0; i < n; ++i) { thread_arg *arg = (thread_arg *) malloc(sizeof(thread_arg)); arg->random_value = random_value; arg->...
0
votes
1answer
27 views

Should a thread always use a while loop to hold a pthread_cond_wait statement?

I understand that spurious wakeups of threads can occur in pthreads. The following discussion was interesting and informative: Why does pthread_cond_wait have spurious wakeups?. My question may be ...
-1
votes
0answers
13 views

Implementing Multi-Threaded Server using Threadpool in C

As a part of my subject project, I have been asked to implement a multi-threaded server model using thread pool, which uses thread pool to handle the multiple requests of clients.I know only basics ...
1
vote
1answer
29 views

How to approach creating threads at a given moment

I need help understanding how to approach the problem I'm trying to solve. I'm writing a program that receives commands to a named pipe from terminal (example: echo "command">pipe). That command has ...
-1
votes
2answers
44 views

C Pthread Priority : Unable to get expected behavior

Here, I am trying to create two threads, assign priorities/policies to them and get the expected behavior. Expected behavior: Thread which has highest priority(in this case, thread1) should execute ...
3
votes
1answer
45 views

Is it legal to call pthread functions on thrd_t?

The C11 support to thread is fine but not exaustive. In case I need to use pthread functions, I would like to understand if it is legal to cast thrd_t to pthread_t. For example: #include <threads....
0
votes
1answer
33 views

Trying to write a buffer to a file, but keep getting segmentation faults and I can't figure out why

I have some code whose goal is to open/create a file, read in messages, and then write those messages to the opened/created file. Everything up to the writing to the file seems to work just fine. Here ...
0
votes
1answer
64 views

Can someone explain this code's logic to me?

I was practicing multithreading and looking for problems online. But i cannot understand the logic behind this chunk of code. The code creates 4 threads and sums the 1/4th part of the array. I know ...
-2
votes
3answers
73 views

Segmentation fault threads

I have written this code that simulates a parking system, however I have a problem when I have to reuse a struct that contains a messageQueue to my carthread. The problem occurs when I try to ...
1
vote
1answer
66 views

Why doesn't the semaphore block the second thread? (C)

I want to write a simple C program to understand the semaphores better. There are two threads and they both call the same function. The first one, increases the global variable and the second thread, ...
-1
votes
0answers
31 views

Comple SDL 1.2 + pthreads code intended for MiniGW under *NIX?

I have some C++ / SDL 1.2 code written approx. 10 years ago by someone else that I'd like to compile and run. The code was intended to compile for both Win32 and Nintendo DS targets using miniGW + ...
1
vote
0answers
29 views

CMAKE do not see thread library [closed]

I tried all under the topic of cmake. But I couldn't compiler the this code. Could you help where is the fault? If main.cpp includes ITimer class every thing is fine. But If I seperate different file ....
0
votes
0answers
32 views

learning to use pthread, what's the correct syntax to pass a pthread as a parameter when calling function master_Level()?

something I tried, error: pthreads undeclared mostly confused about how to pass the pthreads correctly in each part marked in comments int main(){ ... pthread_t p_threads[...
2
votes
1answer
43 views

How to create a variable number of pthreads?

A part of a programming assignment I have at college specifies: for the threads, initialize a large array of pthread_t* in main() and dynamically create pthread_t for each new student using ...
0
votes
1answer
61 views

How to create 2 threads in C?

Currently trying to learn how to implement 2 threads where one does a summation and one does an average. I already have the summation function and average is just average = (sum/i). Do I need another ...
0
votes
1answer
24 views

how to make user custom signal SIGRTMIN unique?

I'm writing a library and need to send a custom signal to threads, I used signal(SIGRTMIN, handler); and all works fine. Since this is a library, I'm worried that some one who used my library will ...
0
votes
0answers
33 views

Why releasing a lock must be performed atomically?

I was looking at process synchronization , and i couldn't figure out why releasing a lock must be peformed atomically , in acquiring lock it's obvioius that it must be performed atomically , since ...
0
votes
1answer
44 views

Problem in communication of three threads in C language (deadlock occurs)

I am creating a program in which i have 3 linked lists and I am trying to update or remove the nodes from these linked lists in these three threads. But the deadlock is occurring The insertion and ...
-2
votes
1answer
52 views

On the website: godbolt.org, and only there: how can I use std::thread?

Here is my code: #include <thread> #include <chrono> using namespace std::literals::chrono_literals; #include <iostream> void f(int n) { for (int cnt = 0; cnt < n; ++cnt) { ...
0
votes
0answers
7 views

laravel DB::transaction doesn't start within a Thread

Consider this code, it's pretty self-explanatory: <?php class TestController extends BaseController { public static $buffer,$num,$stderr; public static function test(){ //phpinfo()...
1
vote
0answers
58 views

Explanation why std::this_thread::sleep_for() sleep time differs between MSVC and MinGW-GCC?

Identifying the Problem I was busy editing a library for lua bindings to rtmidi. I wanted to fix MinGW-GCC and LLVM/Clang compilation compability. When I was done making the edits and compiling the ...
1
vote
1answer
51 views

Convert sequential loop into parallel in C using pthreads

I would like to apply a pretty simple straightforward calculation on a n-by-d-dimensional array. The goal is to convert the sequential calculation to a parallel one using pthreads. My question is: ...
0
votes
1answer
38 views

pthread_join hangs accordingly to random global variable value

I have built this code utilizing pthreads. The goal is to build an array X[N][D] and assign random values to it. You could read the elements of this array as the coefficients of some points. On the ...
0
votes
1answer
36 views

A OS homework problem about executing threads using semaphores

I'm doing my os homework, and the requirement is to implement parallel merge sort using Pthread and using semaphore to lock and unlock them. You can only look at the function names Multi____ and ...
0
votes
2answers
53 views

segfault at pthread_mutex_lock()

I have a code which prints some data structure. void print_wheel_timer(wheel_timer_t *wt){ <code to print data structure> } Then i sandwiched the code in-between lock and unlock mutex calls. ...
0
votes
1answer
64 views

Sharing resources(files, mutexes) between threads

I'm writing a C++ class, that controls serial port (RS232) on GNU/Linux and I have decided (based on number of articles concerning Async I/O on Linux) to use multiple threads in which blocking read/...
0
votes
1answer
24 views

pthread_join wrong type of argument

I've been trying to create a simple thread that reads from stdin and stores input to a linked list. When creating and joining the thread I get the following error: warning: passing argument 1 of ‘...
0
votes
0answers
23 views

Pthread identifying number increases and causes loop to not perform properly

EDIT: I fixed the issue by getting rid of the structure and passing in a copy of the loop parameter. //The struct that gets passed in to threadsafe function struct threading_struct { cell *...
0
votes
1answer
48 views

How to execute the statement after sigwait

I am trying to learn about signals. I have written a small piece of code using sigwait and pthread_kill. The statement after sigwait is not getting executed even if I have issued the signal using ...
0
votes
1answer
33 views

debugging a running daemon with GDB

I want to debug a running daemon with the GDB. I have the process id of respective process. I typed : gdb attach process id info threads I am getting the list of threads. * one is the current one ...
2
votes
2answers
38 views

How capture derivated this in base class into lambda function?

I want to code a program that implements a base class and a derivated one of it. I have to execute a thread in the base class that call a pure virtual function implemented into the derivated class. ...
0
votes
1answer
39 views

Trouble implementing multi-threading across sockets in C program

I'm creating a client-server chat program in C using sockets and threads and having an issue implementing multi-threading. What I have currently got is a server that takes connections from clients ...
-1
votes
0answers
33 views

Segmentation fault when passing argv[i] to pthread

Problem I'm writing a program that uses threads to do actions on files given as arguments. The threads are supposed to use one of the arguments to run work() but it is giving me a segmentation fault ...
2
votes
0answers
21 views

Why does xlib interfere XNVCtrl calls? [duplicate]

I am practicing with threads in C. My program have to constantly (periodically) poll free GPU memory (and other info), while being able to handle X events. The problem is when I am calling ...