Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to pass struct to pthread_create

Posted on 2003-03-19
1
Medium Priority
?
1,735 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

579 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