473,387 Members | 1,760 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.

Re: Question on C++ Thread Class and inheritance/polymorphism withPOSIX pthread

On Oct 27, 10:55*am, alexroat <alexr...@gmail.comwrote:
The strange thing is that's happen only using threads.
Really? What do you get with this code:

#include <stdio.h>
#include <pthread.h>

class Thread
{
public:
Thread(void) { ; }
virtual ~Thread() { run(); }
virtual void run(void);
};

void Thread::run(void)
{
printf("Base\n");
}

class MyThread : public Thread
{
public:
virtual void run(void);
};

void MyThread::run(void)
{
printf("Derived\n");
}

int main(void)
{
MyThread mt;
}

You need to join the thread *BEFORE* you destroy the object. You
cannot destroy even some of the object while the thread is still
running.

DS
Oct 28 '08 #1
0 1785

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

Similar topics

0
by: Tseng, Ling-hua | last post by:
As the comments of the following C++ code, I got the ambiguous error in the specialized class " PThreadTimer<void *(*)(void *)> ". I performed the virtual inheritance mechanism on its base classes...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
0
by: hecklar | last post by:
I'm having a problem with threading (permissions?) in a VB.net Windows application (background service). I'm trying to write an application that processes files, launching a new thread for each...
5
by: Martin Jørgensen | last post by:
Hi, Consider this code: --- beginning of code --- #include <iostream> using namespace std; class Child{ public:
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
4
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global...
1
by: Ian Collins | last post by:
Chris M. Thomasson wrote: Why bother with all that nonsense when there is a standard solution? -- Ian Collins
0
by: JoelKatz | last post by:
On Oct 27, 11:43 am, Ian Collins <ian-n...@hotmail.comwrote: So close, but not quite. Actually, 'main' can't return because the destructor calls 'pthread_join'. In fact, his problem is that...
1
by: Chris M. Thomasson | last post by:
FWIW, here is a quick example (in the form of a fully compliable program with error checking omitted) of how I use POSIX threads within a C++ environment:...
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.