• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
C++ and odd pthread behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ and odd pthread behavior


  • Subject: C++ and odd pthread behavior
  • From: Stuart Smith <email@hidden>
  • Date: Tue, 14 Mar 2006 21:15:19 -0800
  • Thread-topic: C++ and odd pthread behavior

on 3/14/06 8:09 PM, email@hidden at
email@hidden wrote:

> Message: 14
> Date: Tue, 14 Mar 2006 17:23:58 -1000
> From: Kaveh Kardan <email@hidden>
> Subject: C++ and odd pthread behavior
> To: email@hidden
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
> I'm encountering some very odd behavior when running multi-threaded
> code in XCode.
>
> I have 4 threads which allocate tasks, push them onto a stack, and
> pop them off to execute them.  The odd thing is that C++ on occasion
> thinks that the type of an object is actually that of its parent
> class, and calls the parent's method instead of the object's.  If I
> set the number of threads to 1, this does not happen and the code
> runs correctly.
>
> The code also runs correctly with 4 threads on a Linux system.
>
> Has anyone seen anything like this?
>
> Regards,
>
> Kaveh
>
> Kaveh Kardan                 Chief Technologist
> email@hidden             Academy for Creative Media
> (808)956-5302                University of Hawaii

Kaveh,
 You may be calling an overridden function from a constructor.

short demo program:
-----------------------------------------------------------------------
#include <stdio.h>

class Super
{
    public:
        Super::Super();
    virtual int Something() { return 1; }
};

class Sub : public Super
{
    public:
    virtual int Something() { return 2; }
};

// constructor of superclass calls virtual method
Super::Super()
{
    printf("%d\n", Something());
}

int main()
{
    printf("constructing super - ");
    Super  super;
    printf("construcing sub - ");
    Sub        sub;

      printf("and now they're complete\n");
      printf("Super::Something() - %d\n", super.Something());
      printf("Sub::Something() - %d\n", sub.Something());
 }
 -------------------------------------------------------------------

build & run:

stuarts-power-mac-g5:~ stu$ c++ testprog.cp
stuarts-power-mac-g5:~ stu$ ./a.out
constructing super - 1
construcing sub - 1
and now they're complete
Super::Something() - 1
Sub::Something() - 2

from the constructor, only the superclass' Something is called, because at
the time of construction of the Sub class, its overrides are not yet
available.

of course, I may be teaching my grandmother to suck eggs here, and you have
an entirely different problem. If so, I apologise.

hth, Stuart




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Are Xcode updates cumulative or combined?
  • Next by Date: Re: Which debugging bug do you prefer?
  • Previous by thread: Re: C++ and odd pthread behavior
  • Next by thread: Xcode 2.2 vs 1.5
  • Index(es):
    • Date
    • Thread