Thrift PHP singleton without locks? -


i come c++ world.

and recently, started using apache thrift, rpc framework. writing php client code , python server code.

when reading php implementation, find following:

class tstringfuncfactory { private static $_instance;  /**  * singleton instance of tstringfunc implementation  * compatible current system's mbstring.func_overload settings.  *  * @return tstringfunc  */ public static function create() {     if(!self::$_instance) {         self::_setinstance();     }      return self::$_instance; } .... } 

it singleton without locks.

question

what processing pattern of php? guarantee won't happen risk condition.

+1 @n.b.

php (cli or http) exists single thread on single cpu core unless real work make application multithreaded.

how can 1 use multi threading in php applications

for http side, each php execution lives , dies request cycle. server may process several requests concurrently, result in several concurrent php executions, each entirely independent next.

so non-issue. intents , purposes checking static data member satisfies singleton pattern.


Comments