Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97321 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74375 invoked from network); 7 Dec 2016 10:36:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Dec 2016 10:36:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain belski.net from 85.214.73.107 cause and error) X-PHP-List-Original-Sender: anatol.php@belski.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:59924] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/5A-11772-716E7485 for ; Wed, 07 Dec 2016 05:36:08 -0500 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 6D2A0784AA4; Wed, 7 Dec 2016 11:36:04 +0100 (CET) Received: from w530phpdev (p54A7695D.dip0.t-ipconnect.de [84.167.105.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h1123647.serverkompetenz.net (Postfix) with ESMTPSA id 3EF43784AA0; Wed, 7 Dec 2016 11:36:02 +0100 (CET) To: "'simon .barotte'" , References: In-Reply-To: Date: Wed, 7 Dec 2016 11:35:58 +0100 Message-ID: <00e001d25075$b4e4b990$1eae2cb0$@belski.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQExKqspga3t6DOgHpsDCUhinoCZLqI+j/sA Content-Language: en-us Subject: RE: [PHP-DEV] Use pthread in php extension From: anatol.php@belski.net ("Anatol Belski") Hi Simon, > -----Original Message----- > From: simon .barotte [mailto:simon.barotte@gmail.com] > Sent: Tuesday, December 6, 2016 10:49 AM > To: internals@lists.php.net > Subject: [PHP-DEV] Use pthread in php extension >=20 > Hi all, >=20 > I developpe an extension php, and I would like use Linux pthread in my = extension > (PHP 5.6.27). > But I have a feeling that my thread don't work, I looked for the = documentation > but I find no concrete example. > Can I use pthread without zts activated ? Sample of my code : >=20 > void *called_from_thread(void *num){ > php_printf(" print by thread"); > } >=20 > PHP_FUNCTION(test){ > pthread_t inc_x_thread; > int x =3D 0; >=20 > if(pthread_create(&inc_x_thread, NULL, called_from_thread, &x)) { > php_printf("Error creating thread"); > return; > } >=20 > php_printf("This is main print"); >=20 > if(pthread_join(inc_x_thread, NULL)) { > php_printf("Error joining thread"); > return; > } > } >=20 > When I execute my extension in php, I always obtain the same display, = This is > main print print by thread For me the normal behavior of thread would = be to > have different displays sometimes... no ? >=20 Of course you can link your extension with any possible library. = Particularly with pthreads, when PHP is compiled non thread safe, you = need to be very careful using the PHP APIs. Many will be not thread safe = in that case. Best strategy were probably not using PHP APIs in the = thread callbacks at all. Probably a scenario were thinkable, to process some huge amount of data = internally with multiple threads. But you can of course prepare some = data, start threads in some internal PHP function, but don't return from = that function until all the jobs are done.=20 Regards Anatol