473,385 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with pthread_create() - passing argument for start_routine

4
On a Linux platform:
Hi,

I am just trying to pass an integer as an argument to my start_routine when creating a thread with pthread_create:

In my .h file:
short portfd;
void *receive_talker(void* portfd);

In main():
thread_talker is declared as " pthread_t thread_talker; "
pthread_create(&thread_talker,NULL,receive_talker, (void *)portfd); (line 125)

In my .h file:
short portfd;
void *receive_talker(void* portfd);

receive_talker is written like this after main():

void *receive_talker(void *portfd) {
...
}

When compiling, I get the following message:

"warning: cast to pointer from integer of different size "

I also tried:

pthread_create(&thread_talker,NULL,receive_talker, (void *)(&portfd));

then I get:

" Segmentation fault "

...and the execution stops

from a printf("portfd %d\n", (int) portfd )) I can get:

portfd = 268513978 when supposed to be smth like 1 or 2...

I ve got the same 268513978 with :
printf("portfd %d\n", (int *) portfd ))

I guess something is wrong with either the way I pass my variable to the thread or with the way I use the passed variable in my start routine.

I am not so familiar with C so if anybody can help...
Thanks
Mar 27 '07 #1
1 5358
horace1
1,510 Expert 1GB
try making this an int
Expand|Select|Wrap|Line Numbers
  1. int portfd;
Mar 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nightowl | last post by:
Does anybodu know how to do it precisely
1
by: Andreas Müller | last post by:
my problem is probably simple to fix but I don't now how, i have a thread function void *display(struct Camera *camera) and i try to create that thread via pthread_create(&draw_thread,...
12
by: Huskier | last post by:
Hi all: I want to pass a class-member function to pthread_create, and my code is in the following, but I don't know how to pass myobj.thread_function to pthread_create function. #include...
10
by: david wolf | last post by:
The following pthread code cannot compile, I want to know why. Can somebody give me direction on this? if I replace the following line of code status1 = pthread_create(&threadID1, NULL, read,...
6
by: darklupine | last post by:
I'm working on a project for a class at school. In order to complete the project, I have to create a new thread, but I'm not overly certain on how to do so. I have it coded, but it still throws an...
17
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks...
9
by: Gary Wessle | last post by:
Hi I am trying to understand how pthread is used, so I make the scenario below, I could not understand the erros by reading the man pthread_create. //**************** code start...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
1
by: unclefester | last post by:
Could someone please explain to me the return type of pthread_create()'s 3rd parameter? I know it should be a function but I keep getting the error: argument of type 'void' (Test::)(void*)' does not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.