Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50916 Return-Path: <128bitencrypted@googlemail.com> Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51716 invoked from network); 8 Dec 2010 20:50:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Dec 2010 20:50:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=128bitencrypted@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=128bitencrypted@googlemail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.45 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: 128bitencrypted@googlemail.com X-Host-Fingerprint: 209.85.214.45 mail-bw0-f45.google.com Received: from [209.85.214.45] ([209.85.214.45:41382] helo=mail-bw0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/18-04432-C8FEFFC4 for ; Wed, 08 Dec 2010 15:50:21 -0500 Received: by bwz16 with SMTP id 16so1899129bwz.32 for ; Wed, 08 Dec 2010 12:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-enigmail-version:content-type :content-transfer-encoding; bh=T5bpt9SvD2ox5EnXh4Xoqrp1Qyqplo09PXhu6ZMtonU=; b=EP6/8acWu4CjxJ8eh2BpaTmbwJw7023DpLH7FvPXt+Z3opemmPkjDYgoVmskLO44h5 ncXZ7wD7tvBsskMKdhJatJdr+sAUWdKuPjAoTjs7KCoT05t/xu+dJ+/NkQKXyE7Ks3qG 3MJ5p6PX4qL+67ih8eJ9pmOdN/Qg8MEUSRd5Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type:content-transfer-encoding; b=acHnG3nQBb0j1PhTeP0r38i1G0z2BfSQ8RlEikrYMMNQn2OFw9xufy+EeLbJYtEnb0 gsEO+Uoug6WWCuvYnbVRytmU+O144XWe0nvuh05cxkMjt+Fed1scqh4aO9lzcxV3VYk6 M1daoetRzBDhEXBQH2jS1zpdM9iDcE8aBuZoA= Received: by 10.204.75.158 with SMTP id y30mr2430511bkj.126.1291841416832; Wed, 08 Dec 2010 12:50:16 -0800 (PST) Received: from [192.168.178.24] (p5DD2923B.dip0.t-ipconnect.de [93.210.146.59]) by mx.google.com with ESMTPS id v1sm565028bkt.5.2010.12.08.12.50.14 (version=SSLv3 cipher=RC4-MD5); Wed, 08 Dec 2010 12:50:15 -0800 (PST) Message-ID: <4CFFEF85.6030504@gmail.com> Date: Wed, 08 Dec 2010 21:50:13 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: internals@lists.php.net X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: ts_free_thread() frees only temporary in multiple parallel threads From: 128bitencrypted@googlemail.com (Gary Zipfel) I found a solution that solves my problem for almost 99%. Everything gets freed forever now, but there are still some byte per thread left that only get freed at tsrm_shutdown(). I tracked the problem down to the max_execution -timer in zend_execute_API.c where ts_resource_ex() gets called and allocates the resources for my threads that have been already destroyed. So I added a check around it if the target thread is still running so that no more resources will be allocated for the already destroyed ones. But I would be really thankful if someone could tell if this is really the solution or if I'm still missing a detail. To me it looks like a bug in the Zend engine. Heres the patch for PHP 5.2.9: (currently Windows only) *** C:\php529\Zend\zend_execute_API.c.ORIG 2009-01-15 14:23:42.000000000 +0100 --- C:\php529\Zend\zend_execute_API.c 2010-12-08 17:38:26.334868100 +0100 *************** *** 1340,1352 **** #ifdef ZEND_WIN32 static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_REGISTER_ZEND_TIMEOUT: /* wParam is the thread id pointer, lParam is the timeout amount in seconds */ ! if (lParam==0) { KillTimer(timeout_window, wParam); } else { #ifdef ZTS --- 1340,1354 ---- #ifdef ZEND_WIN32 static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + HANDLE target_thread_handle; + switch (message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_REGISTER_ZEND_TIMEOUT: /* wParam is the thread id pointer, lParam is the timeout amount in seconds */ ! if (lParam==0) { KillTimer(timeout_window, wParam); } else { #ifdef ZTS *************** *** 1354,1366 **** #endif SetTimer(timeout_window, wParam, lParam*1000, NULL); #ifdef ZTS ! tsrm_ls = ts_resource_ex(0, &wParam); ! if (!tsrm_ls) { ! /* shouldn't normally happen */ ! break; } ! #endif EG(timed_out) = 0; } break; case WM_UNREGISTER_ZEND_TIMEOUT: --- 1356,1375 ---- #endif SetTimer(timeout_window, wParam, lParam*1000, NULL); #ifdef ZTS ! target_thread_handle = OpenThread(THREAD_QUERY_INFORMATION, FALSE, wParam); ! if(target_thread_handle != NULL) ! { ! tsrm_ls = ts_resource_ex(0, &wParam); ! if (!tsrm_ls) { ! /* shouldn't normally happen */ ! break; ! } ! CloseHandle(target_thread_handle); ! EG(timed_out) = 0; } ! #else EG(timed_out) = 0; + #endif } break; case WM_UNREGISTER_ZEND_TIMEOUT: *************** *** 1370,1384 **** case WM_TIMER: { #ifdef ZTS void ***tsrm_ls; ! ! tsrm_ls = ts_resource_ex(0, &wParam); ! if (!tsrm_ls) { ! /* Thread died before receiving its timeout? */ ! break; } ! #endif KillTimer(timeout_window, wParam); EG(timed_out) = 1; } break; default: --- 1379,1401 ---- case WM_TIMER: { #ifdef ZTS void ***tsrm_ls; ! ! target_thread_handle = OpenThread(THREAD_QUERY_INFORMATION, FALSE, wParam); ! if(target_thread_handle != NULL) ! { ! tsrm_ls = ts_resource_ex(0, &wParam); ! if (!tsrm_ls) { ! /* Thread died before receiving its timeout? */ ! break; ! } ! CloseHandle(target_thread_handle); ! EG(timed_out) = 1; ! KillTimer(timeout_window, wParam); } ! #else KillTimer(timeout_window, wParam); EG(timed_out) = 1; + #endif } break; default: