To: McGuire, Tim Subject: [Solution #118,551,901]: WINDOWS/UNIX: Is it possible to call user defined capsule methods in a capsule's constructor? Hi TJMCGUIR, a couple of little spelling/grammatical problems... ANSWER: This is not possible since it would not be thread safe. When a capsule is incarnated from one thread, on another thread, the capsule's ___he___ constructor is actually called from the incarnating thread even though the capsule runs on the other thread. One method to do this safely is to ___do___ call the user defined methods in the initial transition of the capsule's state diagram. -- below is a snippet from incarnate2.cc ================================================ RTActor * actor = (*actorClass->create)( rts, this ); if( actor == (RTActor *)0 ) { controller->setError( RTController::badClass, RTController::FrameIncarnate, this, 0 ); unreserve( index ); return (RTActor *)0; } actor->_preinitialize( index, _info ); #if USE_THREADS && RTFRAME_THREAD_SAFE lock(); #endif add( actor, index ); if( bind_ports( actor, index, (RTActorRef *)0 ) == 0 ) { #if USE_THREADS && RTFRAME_THREAD_SAFE unlock(); #endif ================================================ It's the *actorClass->create that does the actual construction, and it is not protected by the #if USE_THREADS Isn't the real reason we don't allow customers to create their own Capsule constructors is that there is so much TargetRTS stuff to get right that it would be next to impossible for them to get it all right. (Capsules are purported to be "just a stereotype of a class", but what we don't tell customers is that they require so much TargetRTS support that it's laughable to call them "stereotypes" .) Just on a historical note, ObjecTime didn't allow user defined constructors but did allow destructors. (RoseRT doesn't allow either(?)) In any case "...call the user defined methods in the initial transition of the capsule's state diagram" is the correct alternative whatever the reason you can't do it directly :-) Cheers ________________________________________________ Ian MacWilliam Sr. Technical Support Engineer (613) 591-7922 _________________________________________________ RatiOnal the software development company [Solution #118,551,901]: WINDOWS/UNIX: Is it possible to call user defined capsule methods in a capsule's constructor? Defect ID: # Host: Intel x86 Windows 2000 For Rose-RT(Developer C++) 2002.05.00.305.000 Keywords: capsule, constructor, initialization Solution: QUESTION: Is it possible to call user defined capsule methods in a capsule's constructor? ANSWER: This is not possible since it would not be thread safe. When a capsule is incarnated from one thread, on another thread, the capsule's he constructor is actually called from the incarnating thread even though the capsule runs on the other thread. One method to do this safely is to do call the user defined methods in the initial transition of the capsule's state diagram. Rational Customer Service Policies and Information: http://www.rational.com/support/info.jsp