Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:47:42+00:00 2026-06-14T22:47:42+00:00

I have to do a function that contains two threads. One has to read

  • 0

I have to do a function that contains two threads. One has to read one pipe and the other has to write in another pipe. But I dont know how to pass the pipe yo the thread function, because there is another structure that has to go in the arguments part of the pthread_create.
I’ll put some code if it’s a little clearer this way.

void *readFather(Job *job){
    write (desc1Pipe[0],job->in, job->size_in);
}

void *writeFather(Job *job){
if ((job->size=read (desc2Pipe[1], job->out,  job->max_out) > job->max_out) 
    kill(job->pidhijo,SIGKILL);                        
}

Those are the functions I give to pthread_create.

This is the calling of the threads.

pthread_t pid1; 
pthread_t pid2;
...
pthread_create(&pid1, NULL, readFather, &job);      
pthread_create(&pid2, NULL, writeFather, &job);

Please help me, I’ve done all I can think of, I’m really new to all C related stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:47:43+00:00Added an answer on June 14, 2026 at 10:47 pm

    If you have multiple pieces of data you can wrap them in a struct.

    struct readData
    {
        Job *job;
        int  fd;
    };
    
    ...
    
    struct readData readData;
    
    readData.job = job;
    readData.fd  = pipeFd;
    
    pthread_create(&pid1, NULL, readFather, &readData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that returns a table. The returned table contains (among other
I have a main function that contains two dictionaries that I would like to
I have two code files, one contains my WinMain() function, and all functions related
I have one ViewModel that contains two arrays: arr1 and arr2 . I would
I have a function that contains two for loops, and I'm using a variable
I have a function that returns two values in a list. Both values need
I have a function that counts the amount of visits a page has, and
I have a thread function on Process B that contains a switch to perform
Let's say I have a function that takes a string. That string contains the
In my sample application, I have basically two threads. The main thread contains a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.