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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:07:13+00:00 2026-06-06T19:07:13+00:00

Please see my pseudo-code below. The code comments should explain my problem. I’m new

  • 0

Please see my pseudo-code below. The code comments should explain my problem. I’m new to both pthreads and linked lists in C so I’ve jumped into the deep end a bit. I just need to print the value of str out in the thread_work function. The sequential bit of code is fine but when each thread does its work, it can’t print out the value of str.

// linked list definition
struct linked_list {
   char *str;
   struct linked_list *next;
};

// linked list initiation
struct linked_list *root;
struct linked_list *next_info;
root = malloc( sizeof( struct linked_list ) );

// main code
some loop {
   next_node->str = str;
   printf( "%s\n", next_node ); // PRINTS FINE
   pthread_t thread;
   rc = pthread_create( &thread, NULL, thread_work, (void *) &next_node );
   next_node->next = malloc( sizeof( struct linked_list ) );
   next_node = next_node->next;
}

// code executed by each thread
void *thread_work( void *thread_arg ) {
   struct linked_list *ll;
   ll = ( struct linked_list * )thread_arg;
   printf( "%s\n", ll->str ); // PRINTS SOME MESS (��E#)
}

In my actual code there are a few more members of the linked_list struct.

Many 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-06-06T19:07:14+00:00Added an answer on June 6, 2026 at 7:07 pm

    You have a pointer type mismatch: you are passing a pointer to a pointer to list node, but inside thread_work you treat it as a pointer to node. Either remove the ampersand before next_node in the call to pthread_create, or change your thread_work as follows:

    void *thread_work( void *thread_arg ) {
        struct linked_list **llp, *ll;
        llp = ( struct linked_list ** )thread_arg;
        ll = *llp;
        printf( "%s\n", ll->str ); // PRINTS SOME GOOD STUFF
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see below code: thrust::device_vector<int>::iterator whereToBegin = copyListOfNgramCounteachdoc.begin(); end = thrust::unique_by_key(end.first, end.first + numUniqueNgrams,end.second);
Please see the code snippet below : #include <iostream> using namespace std; int main()
Please see my code below... I am puzzled and want to initially show 30px
Please see the formulæ below. It's the solution to a circle chord problem where
Please see below code,i getting wrong value. eg; var FirstValue=0.00; var secondvalue=parseFloat(22.88,10).toFixed(2); var thirdvalue=(FirstValue)
Please see the code below:- #!/usr/bin/python # Filename: total.py def total(initial=5, *numbers, **keywords): count
Please see code below. DeviceDAO, Device, and Mobileuser are hibernate generated objects. the process
please see below link and help me to fix this problem. http://parsegard.com my problem
Please see each section below for a description of my problem described in three
Please see the code below. I am trying to draw a circle around 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.