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 6601285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:43:59+00:00 2026-05-25T18:43:59+00:00

I have a ressource manager that handles multiple TCP-Connections. These connections are pthreads. How

  • 0

I have a ressource manager that handles multiple TCP-Connections. These connections are pthreads. How can I manage it to send data from the Ressource Manager to all of these threads? Or even better: How can I figure out to which thread I have to send this command?

For example: I have 2 Threads, one with pid 3333, one with pid 4444. The user sends a task to program a board (it is a ressource manager that manages FPGA-boards). The ressource manager picks a board from a list, where also this pid is saved. Then the program-command should be send to the thread with this pid or, what I was thinking in the first place, to all of the threads and the threads decide if they go on or not. Protocol looks like this: <pid>#<board-id>#<file>

I open 2 pipes (for writing to the threads and reading from the threads) in the main.c and give them as an argument to the listening-thread (forthread-struct).

main.c
// open Pipes to SSL
    int rmsslpipe[2];
    int sslrmpipe[2];
    if (pipe(rmsslpipe) == -1) {
        writelog(LOGERROR, "main: could not create RM-SSL reading pipe");
        exit(1);
    }
    if (pipe(sslrmpipe) == -1) {
        writelog(LOGERROR, "main: could not create RM-SSL reading pipe");
        exit(1);
    }
    int rmtosslserver = rmsslpipe[1];
    int sslservertorm = sslrmpipe[0];

    // start SSL-Server as a pthread
    pthread_t thread;
    forthread* ft = malloc(sizeof(forthread));
    ft->rmtosslserver = rmsslpipe[0];
    ft->sslservertorm = sslrmpipe[1];
    pthread_mutex_t ftmutex;
    pthread_mutex_init(&ftmutex, NULL);
    ft->mutex = ftmutex;

    pthread_create(&thread, NULL, startProgramserver, (void*) ft);

This thread now listens for new connections and if there is a new connection, it creates a new thread with the forthread-struct as argument. This thread is where the action happens 🙂

void* startProgramserver(void* ft) {

int sock, s;

forthread* f = (forthread*) ft;

// open TCP-Socket
sock = tcp_listen();

while(1){
    if((s=accept(sock,0,0))<0) {
        printf("Problem accepting");
        // try again
        sleep(60);
        continue;
    }

    writelog(LOGNOTE, "New SSL-Connection accepted");
    f->socket = s;
    pthread_t thread;
    pthread_create(&thread, NULL, serveClient, (void*) f);
}
exit(0);
}

This thread now initializes the connection, gets some information from the client and then waits for the ressource manager to get new commands.

n=read(f->rmtosslserver, bufw, BUFSIZZ);

But this fails if there is more than only one thread. So how can I manage that?

  • 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-05-25T18:43:59+00:00Added an answer on May 25, 2026 at 6:43 pm

    If you have one thread per board, the “pid” shouldn’t be needed in the command — you just need a way to find the right thread (or queue, or whatever) for the specified board.

    You could keep a list of your forthread structures, and include the board ID in the structure. Also include a way of passing commands; this could be a pipe, but you may as well use some sort of queue or list instead. That way you use one pipe (or other mechanism) per thread instead of a single shared one, and can find the right one for each board by searching the forthread list for the one with the right board ID. Just be sure to protect any parts of the structure that may be modified while the thread runs with a mutex.

    The problem with using a single pipe as you’ve suggested is that only one thread will get each command — if it’s the wrong one, too bad; the command is gone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my game I have a concept of resource manager, a class that stores
I am working on an application that tries to streamline data entry from a
I have an app that manages a list of third-party servers and can poll
I have a wizard style interface where I need to collect data from users.
I have couple resource DLLs that I currently load when application starts using following
I have a resource database where resources can belong to different locations. Users and
Consider that I have 1 resource and 2 urls (let's say new one and
Is it possible to have multiple resource bundles in spring mvc? I want to
I have a Windows Mobile application written in Java that uses AWT for the
I have a resource assembly that contains various strings, icons, and bitmaps that my

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.