?
Solved

how to pass struct to pthread_create

Posted on 2003-03-19
1
Medium Priority
?
1,728 Views
Last Modified: 2013-12-26
I have a struct like that:
struct msstruct
{
  .......
  int tid; //thread id
};

struct msstruct ms[no_threads];

I want to pass a struct to pthread_create, such as
pthread_create( &tid[ i ], NULL, compute_thread, (void*)&ms[i])
(ms is an array of struct)
in the function void *compute_thread( void *arg )
I use: int id = (msstruct)arg.tid;

But I was given error like
"request for member `tid' in `arg', which is of non-aggregate
   type `void*'"

Can you tell me what is wrong with this?
0
Comment
Question by:rlin1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
ecw earned 200 total points
ID: 8171547
You need to cast arg back from void * to  struct msstruct *

That is,
  void *compute_thread( void *arg )
  {
  struct msstruct *ms = (struct msstruct *) arg;
  int id = ms-> tid;
/* ... and the rest of your function */
  }


0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question