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

The Archive Base Latest Questions

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

As I could not find a way out using thread specific data for socket

  • 0

As I could not find a way out using thread specific data for socket descriptor as depicted in this question A question on shared library and thread specific data , I am planning to declare a process wide global array with each row having two elements pthread_t and int(for socketfd). So whenever a thread needs to communicate with the server it will look up the array for its socket fd using its identity(pthread_self())and use it to communicate.

But I was wondering instead of dynamically allocating and deallocating space for this structure whenever there is a connection setup or disconnected respectively , if I have a array with the size of say 1000 …is it too big/inefficient(I will have to search too)? 1000 threads will not exist at the same time. so the array will not always be full.

Thanks

  • 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-25T16:59:52+00:00Added an answer on May 25, 2026 at 4:59 pm

    The space required to store an array like this with only 1000 elements will not likely be a problem unless you’re running on very resource limited hardware. As for the performance, it really depends on how frequently you search the array… if the searches won’t occur frequently during the life of each thread, the speed will probably be adequate unless you have very high standards for performance.

    However, if you’re planning on creating a thread for each connection and terminating the thread when done, then a better approach would be to design a structure containing all the information the thread needs from the main program (like the socket file descriptor) and pass a pointer to it as the thread’s argument when you create the thread.

    If you do use a thread per connection, you might also want to look into setting a smaller-than-default stack size for the threads as well, so that creating a large number of threads doesn’t eat too much memory for stack space.

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

Sidebar

Related Questions

I'm surprised that I could not find any info on this. I must be
I could not find any pointers on how to create a menubar icon on
After having a search around I could not find exactly what I want, I
I googled a lot, and could not find a single open source implementation of
Just could not get this one and googling did not help much either.. First
Here is some code I could not get to format properly in markdown, this
Sorry for the slightly rubbish title. I could not think how to describe this
I am currently testing out using OSGi. I am running this through Eclipse. I
Is there a way to find the number of files of a specific type
I hope this question does not come off as broad as it may seem

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.