Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19433 invoked by uid 1010); 11 Nov 2005 17:29:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 19418 invoked from network); 11 Nov 2005 17:29:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2005 17:29:09 -0000 X-Host-Fingerprint: 209.10.209.56 gw1-ss-fe0.spikesource.com Linux 2.4/2.6 Received: from ([209.10.209.56:30655] helo=mail.spikesource.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id CC/2D-03704-3E4D4734 for ; Fri, 11 Nov 2005 12:29:07 -0500 Received: from ganges.spikesource.com (ganges.spikesource.com [::ffff:172.16.20.210]) (SSL: TLSv1/SSLv3,128bits,RC4-MD5) by mail.spikesource.com with esmtp; Fri, 11 Nov 2005 09:29:00 -0800 id 0012808C.4374D4DC.00006007 Reply-To: enugroho@spikesource.com To: internals@lists.php.net Organization: SpikeSource Inc. Date: Fri, 11 Nov 2005 09:29:00 -0800 Message-ID: <1131730140.30983.2.camel@ganges.spikesource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Mailer: Evolution 2.0.4 (2.0.4-7) Subject: Array_merge, safety and race condition? From: enugroho@spikesource.com (Ezra Nugroho) I sent this to the general list, but I didn't get definitive answer. Maybe internals is the better forum to talk about it. If you have a test code, or other pointers towards a definitive answer, I'd love to try it. Thanks Php experts everywhere, I want to merge two arrays, and I want to store the result as the first array. Something like the following: $array1 = array_merge ($array1, $array2); So far the code gives me what I want. However, suppose if $array1 is extremely huge, am I introducing a bug here because of possible race condition? It's possible that array_merge has two write something to $array1 (left hand side) before it even finishes reading it (argument) in the first place. Let alone merging the two. Should I just go conservative and do: $tmp = array_merge($array1, $array2); $array1 = $tmp; Thank you, Ezra