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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a36a9db79cd4c60d X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!o9g2000vbj.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada and MySQL (mysql_library_init) Date: Sun, 6 Dec 2009 12:49:21 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <1f1dd31f-dc98-43b1-9f28-6af11292dd46@h2g2000vbd.googlegroups.com> NNTP-Posting-Host: 83.76.199.32 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1260132562 12751 127.0.0.1 (6 Dec 2009 20:49:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 6 Dec 2009 20:49:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o9g2000vbj.googlegroups.com; posting-host=83.76.199.32; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8326 Date: 2009-12-06T12:49:21-08:00 List-Id: On 6 Gru, 14:06, Tomek Walkuski wrote: > MySQL docs say: > > "In a nonmulti-threaded environment, the call to mysql_library_init() > may be omitted, because mysql_init() =A0will invoke it automatically as > necessary. However, mysql_library_init() is not thread-safe in a multi- > threaded environment, and thus neither is mysql_init(), which calls > mysql_library_init(). You must either call mysql_library_init() =A0prior > to spawning any threads, or else use a mutex to protect the call, > whether you invoke mysql_library_init() or indirectly via mysql_init > (). This should be done prior to any other client library call." > > So in multi-threaded environment mysql_library_init CANNOT be ommited. Of course it can, and even the docs that you cite above tells you under what conditions it can be done. If you plan to use *that* function from multiple threads, you have to protect it with a mutex. It is dead obvious that you might also ensure by other means that there is only one thread that calls this function and if you do ensure that, everything is OK - even if later on you will have many threads creating the actual connections and interacting with the database. Don't be mislead by this "multi-threaded environment" horror. Every single program that is in principle "multi-threaded" has or can be restructured to have some initialization phase when it is purely single-threaded and this is a perfect place to put initialization calls that are not themselves thread-safe. Coming back to MySQL and database clients in general - I would be surprised to see a program that lazily "initializes" the database environment in the context that is already multi-threaded. This part of documentation probably reflects the most frequent use-case for MySQL, which is in web applications implemented in terms of reactive "scripts" (think about PHP): indeed, there is no explicit initialization phase and potentially any action might trigger the initialization calls. But if you write in Ada you can do better (even with AWS). > And how about mysql_library_end() ? I could not import it to Ada and > this function performs some memory clean up after disconnection. I think that the world will not end tomorrow if you "forget" to call it. Think about programs that never finish and/or that use the database all the time - these programs, well, don't call it. And really - what is exactly your problem with importing these two functions? Let me guess - they are *macros*. What a mess... (checking the mysql.h header ... yes, they are macros) -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada