All Questions

Tagged with
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
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 ...
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
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
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
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 ...
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, ...
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
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 ...
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
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
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 ...
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 ...
0
votes
0answers
29 views

Client-Server: How to handle incoming server response(s) (while loop) in multi-threads in client? [C Program]

So I have a server that sends a response object in a while loop. The while loop continues until x number of response objects is sent to the client. I want to handle the incoming requests in threads (...
0
votes
1answer
49 views

Why does valgrind report different results (no leaks are possible / still reachable) just by running the program multiple times?

While debugging a random segmentation fault, I ran valgrind, running the same program multiple times I get different results. Here is a simplified version of the program (I did not get a a random ...
-6
votes
0answers
37 views

Pthreads using mutex

Multiple Producer–Multiple Consumer (MPMC) Problem In the lecture, we talked about how to use semaphores to solve the producer-consumer problem. In fact, the solution supports multiple producer ...
1
vote
2answers
87 views

Unable to get correct nanoseconds time interval

My code is unable to capture proper running time of my program. I want to display program execution time only in nanoseconds. I have used clock_monotonic to calculate time. In my code i have used ...
0
votes
0answers
56 views

How to destroy a mutex if no thread is locked on it?

Is there any way using pthread which allows us to implement a system such that the last thread unlocking a mutex also destroys it? Here last means that no other thread is locked on the mutex when ...
-1
votes
0answers
26 views

How to have a equal reader writer priority Pthread program in C?

I'm trying to write a pthread program for the readers writers problem with equal reader and writer priority (when there are one writer and one reader, both should have the same probability of ...
0
votes
0answers
43 views

pthread_mutex_lock can't acquire lock

There are two applications: one sending signals and one receiving them. I want to share mutex, conditional variable and flag between these two applications. My solution using mmap works with only one ...
0
votes
1answer
22 views

Access Struct members after pass to pthread function call

I am trying to access members of my struct that is passed to a function that was called by a pthread process. It is simple, but for some reason I cannot figure it out. I have tried using data.count ...
0
votes
0answers
16 views

2 bounder buffers shared with pthread calls, mutex locks and busy waiting

I am generally new to C so I have loads of syntax errors and referencing problems. I have written prodcons.c, a Struct that will create a bounded buffer of size 50 and a few helper variables. In main ...
0
votes
0answers
36 views

Why does Cygwin gdb have a problem debugging a program with threads?

I am having trouble debugging programs with threads on Cygwin. When the following program gets to the pthread_create() call, the debug session gets an unknown target exception, apparently in a call ...
-1
votes
0answers
23 views

A pthread mutex with two conditions

I can't make a pthread run correctly with one mutex and two conditions. My goal is to make the staff wait until the store is opened_for_staff and after it is opened, go in, and react to every ...
0
votes
0answers
31 views

How to get two concurrent threads to listen to one input?

I'm making a multithreaded console game where I have to move an actor and shoot the enemies. Moving and shooting are two different threads and they both must listen to the keyboard input. I've tried ...
0
votes
2answers
37 views

New to using p_thread & semaphores, how would you use a semaphore to wait for a child thread to finish? (without p_thread join)

New to using p_thread & semaphores, how would you use a semaphore to wait for a child thread to finish? (without p_thread join)
0
votes
1answer
36 views

Deadlock Prevention, random thread execution order C

I am building a program for a school assignment. It has the following requirements as shown below. Must use Mutexes Must use Pthreads Create 5 threads with random synchronization (aka: running in a ...
0
votes
0answers
30 views

How to limit concurrent threads running in c and get return value of each thread after it finishes executing (pthread)

I would like to limit to amount of concurrent threads when using the pthread_create() function. In my application now, i am currently starting a bunch of threads using pthread_create() but have no ...
3
votes
2answers
49 views

Why can't I pass my “for” index directly to a pthread_create call?

#define THREADS_NUMBER 10 Given a function f: void *f(void *arg){ pthread_mutex_lock(&mutex); printf("%i\n", *((int*) arg); pthread_mutex_unlock(&mutex); } I don't understand ...
0
votes
0answers
38 views

How to control multiple instances of the same pthread to process a sequential list

I have a linked list which will be processed by n instances of the same pthread. The thread will continuously remove an item from the list and depending on the type will move it to a second list, ...
0
votes
1answer
28 views

Struct data passed into pthread_create is incorrect when read

In the below code I am trying to pass a struct into pthread_create. The struct is defined globally. It is then initialized before calling pthread_create. // Global scope struct dat_struct { char *...
0
votes
1answer
31 views

Checking the value of pthread_cond_t

I am trying to check the value of a variable of type pthread_cond_t in a while loop condition. The variable is defined in a node struct with the following form: pthread_cond_t cv; When I try to ...