From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86f62fb0f98ad93e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Passing Ada Proc as a C Function Pointer Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Wed, 4 Aug 2010 21:36:38 +0200 Message-ID: NNTP-Posting-Date: 04 Aug 2010 21:36:35 CEST NNTP-Posting-Host: 38f66d5c.newsspool3.arcor-online.net X-Trace: DXC=TCT1@I>K=Gmm7>ihJR;B_cMcF=Q^Z^V3h4Fo<]lROoRa8kFOW4edINk[6LHn;2LCVn[ On Wed, 04 Aug 2010 11:46:56 -0700, Jeffrey Carter wrote: > procedure Thread_Proc : out Thread_Context; > Proc : in Thread_Proc; > Stack : out Stack_Area) > is > type C_Context is ...; > -- Something C-compatible that corresponds to the C > -- definition of avr_thread_context, using only > -- convention-C components. > pragma Convention (C, C_Context); > > procedure Local_Proc is > -- null; > begin -- Local_Proc > Proc.all; > end Local_Proc; > pragma Convention (C, Local_Proc); I am not sure if this works everywhere. The problem is that Local_Proc refers to a local variable Proc (formal parameter of Thread_Start). This needs some special techniques on the compiler side to become C-conform, e.g. a trampoline. Local_Proc should be moved out of Thread_Proc. Then a copy of Proc is created in the scope of. That would be not task safe without a protected object around the copy of Proc. Another way could be passing a copy of Proc on Thread_Context. But IMO there is nothing with putting C conventions on Ada callbacks. All bindings I know, use it without hesitation. > Are Context and Stack really needed outside Thread_Start? In any case they need to be collected upon thread completion. Therefore they must come from outside (unless Thread_Proc could free them, which is unlikely). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de