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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:12:54+00:00 2026-05-29T06:12:54+00:00

Let’s say I have a text file composed like this ##### typeofthread1 ##### typeofthread2

  • 0

Let’s say I have a text file composed like this

#####
typeofthread1

#####
typeofthread2

etc…

in my main I want to read that file, get the strings typeofthread1, typeofthread2 and create different threads using

pthread_t threads[NUM_THREADS];
for (i=0;i<NUM_THREADS;i++)
    pthread_create(&threads[i], NULL, -> HERE <- , void * arg);

how can I put the just read typeofthread1, typeofthread2 strings into -> HERE <- making the main create two threads that point to two different thread prototype?

I want to do this because I want to create a program that creates different types of threads, depending on what I want to do, and choosing that from text file (sort of a configuration file)

any suggestion?

  • 1 1 Answer
  • 2 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-29T06:12:54+00:00Added an answer on May 29, 2026 at 6:12 am

    Map the string names to function pointers.

    void * thread_type_1 ( void * );
    void * thread_type_2 ( void * );
    
    typedef  void * (*start_routine_t)(void *);
    
    typedef struct mapping_t {
    
         const char * name;
         start_routine_t function;
    
    } mapping_t;
    
    const mapping_t mappings[] = {
        {"thread-type-1", &thread_type_1},
        {"thread-type-2", &thread_type_2},
    };
    const size_t mapping_count =
        sizeof(mappings)/sizeof(mappings[0]);
    

    To select the proper thread function, loop over items in mappings and grab the function when the name matches.

    start_routine_t get_start_routine ( const char * name )
    {
        size_t i;
        for ( i=0; i < mapping_count; ++i )
        {
            if (strcmp(name,mappings[i].name) == 0) {
                return mappings[i].function;
            }
        }
        return NULL;
    }
    

    In wherever you launch the thread, you can use this as:

    start_routine_t start_routine;
    
    /* find start routine matching token from file. */
    start_routine = get_start_routine(name);
    if (start_routine == NULL) {
        /* invalid type name, handle error. */
    }
    
    /* launch thread of the appropriate type. */
    pthread_create(&threads[i], NULL, start_routine, (void*)arg);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say that I have classes like this: public class Parent { public int
Let's say i have this block of code, <div id=id1> This is some text
Let's say i have input 22365.2588 in my Edit Text. I want to change
Let's say I have a drive such as C:\ , and I want to
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.