|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20495 BC Math is not Thread Safe, but is in Win32 TS distribution
Submitted: 2002-11-19 09:14 UTC Modified: 2002-12-02 22:00 UTC
From: msisolak at yahoo dot com Assigned:
Status: Closed Package: BC math related
PHP Version: 4.3.0RC1 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: msisolak at yahoo dot com
New email:
PHP Version: OS:


 [2002-11-19 09:14 UTC] msisolak at yahoo dot com
I'm adding this bug report to make sure it doesn't get lost.  I would ask that this be marked critial for 4.3.0 release.  The current thread safe Win32 build is _not_ thread safe because it includes BC Math as a built-in extension, but BC Math is not thread safe.

Here is what I said on the php-dev list:
> > I'm seeing a memory overrun under PHP 4.3.0pre2 (debug) running under
> > Windows 2000 ISAPI.  [ . . . ]
> > ---------------------------------------
> > C:\Work\php-source\php-4.3.0pre2\ext\bcmath\libbcmath\src\init.c(72):
> > Freeing 0x01B85050 (1 bytes), script=c:\inetpub\wwwroot\test.php
> > Last leak repeated 2 times
> > C:\Work\php-source\php-4.3.0pre2\ext\bcmath\libbcmath\src\init.c(57):
> > Freeing 0x01B84FF8 (29 bytes), script=c:\inetpub\wwwroot\test.php
> > Last leak repeated 2 times
>Based on seeing these leaks I disabled BCMath and recompiled PHP.
>Without BCMath active I do not have any of the memory overruns that I
>reported in my previous message.
>Looking in the CVS logs for php4/ext/bcmath/bcmath.c I believe there
>may be an issue with the changes introduced in version 1.37 (by Andi,
>who is CCed also).  This patch moved the allocation and freeing of the
>static BC numbers _zero_, _one_, and _two_ to a per-request basis
>instead of at module initilzation and shutdown.  It looks like the
>storage locations for those values are global externs, however, which
>multiple threads are now allocating and deallocating at the same time.
>Is there somewhere that I'm not understanding in the code that would
>keep multiple threads from smashing each other here?

And these were Andi's responses:

> > You are right. I screwed up. I have to make these TSRM globals.
> > I'll try and do it tomorrow.
> Adding a BCMATH_G() TSRM macro around all instances of _one_, _two_ and 
> _zero_ seems to be quite a pain because it means that libbcmath needs to 
> understand TSRM now.
> On the other hand these three variables need to be per-request because 
> emalloc()'ed memory can't survive in between requests.
> Does anyone have any interesting solutions? If not I guess we can start 
> hacking at the libbcmath sources.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-02 22:00 UTC] msisolak at yahoo dot com
Fixed in CVS for 4.3.0RC2.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 13:01:29 2024 UTC