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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5d05ccde5cefb836 X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Tasks and C/C++ code. Date: 1998/11/10 Message-ID: <729ndu$jfo$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 410325729 References: <364702E5.F6987321@hiwaay.net> X-Http-Proxy: 1.0 x7.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Nov 10 15:51:26 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I) Date: 1998-11-10T00:00:00+00:00 List-Id: In article <364702E5.F6987321@hiwaay.net>, bdorough@phaseiv.com wrote: > I am working on a project where we need to call the same C function > from multiple tasks. I am wondering how to do this safely. Can I make > a generic with my C pragma defined there are do I need to define the > prama in the task type so each task will have its own copy of the C > function. If the C function truly isn't safe to call from multiple threads (iaw: relies on global data, "static" local declarations, or calls other non-thread safe routines) then you have to ensure that calls to it happen from only one thread. The safest way to do it is to make *one* server task responsible for calling the routine and returning its results. Client tasks rendezvous with the server task to request a call to the unsafe C routine. This is the method used in at least one set of X/Motif Ada bindings. A generic won't do any good, because you end up with multiple bindings to the *same* C routine, not multiple copies of the C routine itself. A task type won't work for roughly the same reason, unless you only allow *one* object of that type. Even then you could have problems with object caching and thread-local data. -- T.E.D. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own