473,387 Members | 1,899 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,387 software developers and data experts.

Problem creating new posix thread

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 error, and I
can't figure out why it is doing so.

The create line reads:

pthread_create(&thread1, NULL, (void *)&CourNet::recieve, NULL);

CourNet is my class name, and recieve is the function I'll be calling.
recieve returns (NULL) and its header is the following:

void * CourNet::recieve(void * pointer)

The error it returns when I try to compile (using g++, I'm not sure
what version it is) is as follows:

CourNet.cpp:103: converting from 'void*(CourNet::*)(void*)' to 'void*'
CourNet.cpp:103: invalid conversion from 'void*' to 'void*(*)(void*)'

I've mucked with the code a bit trying to fix it, adding the void *
return type on recieve instead of a regular void, and adding the void *
pointer parameter, as well as the return (NULL).

Can anyone give me any suggestions on how I might correct this error?
If you need any more information, let me know.

Thanks!

Nov 24 '05 #1
6 2331
darklupine wrote:
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 error, and I
can't figure out why it is doing so.

The create line reads:

pthread_create(&thread1, NULL, (void *)&CourNet::recieve, NULL);

CourNet is my class name, and recieve is the function I'll be calling.
recieve returns (NULL) and its header is the following:

void * CourNet::recieve(void * pointer)

The error it returns when I try to compile (using g++, I'm not sure
what version it is) is as follows:

CourNet.cpp:103: converting from 'void*(CourNet::*)(void*)' to 'void*'
CourNet.cpp:103: invalid conversion from 'void*' to 'void*(*)(void*)'

I've mucked with the code a bit trying to fix it, adding the void *
return type on recieve instead of a regular void, and adding the void *
pointer parameter, as well as the return (NULL).

Can anyone give me any suggestions on how I might correct this error?
If you need any more information, let me know.

Thanks!

Without getting into any specifics about using the pthread calls (which
would be off topic here) I advise you to read the errors carefully.

Think about what pthread_create expects as its third argument (hint:
it's *not* a member function; functions and member functions are two
different things).

Next thing to do is a Google search; believe it or not, you're not the
first to encounter this! [;-)]

Oh -- and it's `receive'.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
Nov 24 '05 #2
Hmm...I think I may have cleared it up. If I am undestanding you
correctly, and its not making some runtime error or somesuch, moving
the recieve function (now that I know its mispelled, I'll go back and
fix the spelling...oops!) outside of the class and changing the
pthread_create call to:

pthread_create(&thread1, NULL, &recieve, NULL);

seems to have fixed the error. Thanks a lot! Neither of my profs are
overly familiar with threading, and I've been basically teaching
myself. Wish I had thought to come here earlier, instead of pounding my
head against the wall...

Nov 24 '05 #3
Ian
darklupine wrote:
Hmm...I think I may have cleared it up. If I am undestanding you
correctly, and its not making some runtime error or somesuch, moving
the recieve function (now that I know its mispelled, I'll go back and
fix the spelling...oops!) outside of the class and changing the
pthread_create call to:

pthread_create(&thread1, NULL, &recieve, NULL);

To be strictly correct (which is a good thing if you are learning!),
declare receive an extern "C" function.

extern "C" {
void* receive( void* );
}

Always do this when passing a C++ function pointer to a C library.

Ian
Nov 24 '05 #4
darklupine wrote:
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 error, and I
can't figure out why it is doing so.

The create line reads:

pthread_create(&thread1, NULL, (void *)&CourNet::recieve, NULL);

CourNet is my class name, and recieve is the function I'll be calling.
recieve returns (NULL) and its header is the following:

void * CourNet::recieve(void * pointer)


Look at the posix thread layer in Austria C++.

You REALLY want a layer like this. This works for both win32 and *nix
systems.
Nov 25 '05 #5
ben
darklupine wrote:
Hmm...I think I may have cleared it up. If I am undestanding you
correctly, and its not making some runtime error or somesuch, moving
the recieve function (now that I know its mispelled, I'll go back and
fix the spelling...oops!) outside of the class and changing the
pthread_create call to:

pthread_create(&thread1, NULL, &recieve, NULL);

seems to have fixed the error. Thanks a lot! Neither of my profs are
overly familiar with threading, and I've been basically teaching
myself. Wish I had thought to come here earlier, instead of pounding my
head against the wall...

You can still put your function in a class, but make it static.
Nov 26 '05 #6
Ian
ben wrote:
darklupine wrote:
Hmm...I think I may have cleared it up. If I am undestanding you
correctly, and its not making some runtime error or somesuch, moving
the recieve function (now that I know its mispelled, I'll go back and
fix the spelling...oops!) outside of the class and changing the
pthread_create call to:

pthread_create(&thread1, NULL, &recieve, NULL);

seems to have fixed the error. Thanks a lot! Neither of my profs are
overly familiar with threading, and I've been basically teaching
myself. Wish I had thought to come here earlier, instead of pounding my
head against the wall...

You can still put your function in a class, but make it static.


No, make it an extern "C" friend.

Ian
Nov 26 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Evan David Light | last post by:
After agonizing over this problem for a few days, I've decided to seek help. No, not the variety that involes a jacket that zips up the back but this august body of intrepid individuals. I've...
6
by: Christian Buckl | last post by:
Hi, I try to implement my own thread class based on POSIX threads. I want my class to manage everything (creation of threads, exception handling...). This includes also some functions that need to...
11
by: Ian Bell | last post by:
Apologies for the last post; got the topic wrong. What is the current thinking on the best way to solve the shared data problem i.e. accesssing a shared variable in a non atomic way can give...
3
by: vaddadi.chandu | last post by:
I am writing a multithreaded web-server and multithreaded client in C. The server is required to keep a log of the transactions in a local file. I try to open a file using the following: FILE...
7
by: DBMS_Plumber | last post by:
Having a hard time with a UDF. Wonder if folk might care to take a look and tell me what's up. All of this kicked off from trying to build a set of C++ iostream derived classes that can make...
23
by: Boltar | last post by:
Hi I'm writing a threading class using posix threads on unix with each thread being run by an object instance. One thing I'm not sure about is , if I do the following: myclass::~myclass() {...
2
by: jiang.haiyun | last post by:
Hi, I am having some serious problems with PyQT4, when i run pyqt script, I always get 'Segmentation fault'. the script is simple: ====================== %less qttest.py from PyQt4 import...
18
by: mati | last post by:
Hi The following code works: #include <vector> class C { private: static const int m_static = 2; public: void f(const std::vector<int>& v)
3
by: psroga | last post by:
Can anyone look at this code and let me know why pthread_mutex_unlock and pthread_mutex_lock are giving me the "phtread_mutex_unlock" was not defined in this scope error. I am compiling the code...
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:
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.