GithubHelp home page GithubHelp logo

Bug Static member about pthreads HOT 5 CLOSED

krakjoe avatar krakjoe commented on August 15, 2024
Bug Static member

from pthreads.

Comments (5)

krakjoe avatar krakjoe commented on August 15, 2024

I will assume that the example you posted was correct when you ran it.

I can see a leak and a segfault when I run a variation of it, which shouldn't happen. But static variables do not have the abilities or functionality you are trying to use here and should be avoided completely if at all possible, they cannot be used in a truly safe manner. They cannot be shared among threads safely, and your code will be more stable and safe if you do not use them.

EDIT: I thought you were someone else, have a look through previous bugs concerning static variables, it's been discussed before, I'm sorry it's not documented yet I just haven't had the time ...

from pthreads.

bride avatar bride commented on August 15, 2024

I did another test, error occurs using self, if access using

// Error
public static function get() {
if (!self::$instance)
self::$instance = new self;
return self::$instance;
}

//Works with access static property in thread

public function get() {
if (!$this::$instance)
$this::$instance = new self;
return $this::$instance;
}

//Works with access static property in thread

public static function get() {
if (!MyThread::$instance)
MyThread::$instance = new self;
return MyThread::$instance;
}

from pthreads.

krakjoe avatar krakjoe commented on August 15, 2024

Could you please provide full, properly formatted examples, I think I understand what you're saying but it'd be nice to be certain :)

Thanks for taking the time to keep looking, it's very helpful ...

from pthreads.

bride avatar bride commented on August 15, 2024

I have a meeting now, will post later.
what I mean is:

  • self :: $ propertyName does not work in the context of the thread (static properties).
  • MyThread::$propertyName and $this::$propertyName work in the context of the thread (static properties).

from pthreads.

krakjoe avatar krakjoe commented on August 15, 2024

Ah right yeah that makes sense, both $this and the entry are declared for the actual threading context explicitly, I guess I need to handle the self keyword somehow, I will look into it ... cheers

from pthreads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.