1. [Phix] Question About Assignment

Pete, I notice in some of your code you do this:

my_var = repeat(' ',0)

instead of

my_var = ""

I'm just curious as to why! grin

new topic     » topic index » view message » categorize

2. Re: [Phix] Question About Assignment

Thread safety. If multiple threads are calling (eg) [s]printf(), and that was using a common shared "" constant, they c/would stomp all over each other's reference counts, so using repeat(' ',0) instead of "" creates a new private thread-specific (and in fact call-specific) string, obviously with a private reference count that no other thread can possibly access.

If you have a (hidden) reference count of 2, and (without either locking or privacy) one thread increments it at the exact same time as another decrements it, you will end up with either 1 or 3 instead of the desired 2.

Naturally the reference count on a constant should never drop below 1, and catastrophy ensues if it ever does, but it is incremented to trigger either copy-on-write processing or a p2js violation under "with js".

new topic     » goto parent     » topic index » view message » categorize

3. Re: [Phix] Question About Assignment

<duplicate post>

new topic     » goto parent     » topic index » view message » categorize

4. Re: [Phix] Question About Assignment

petelomax said...

Thread safety.

Ahh, OK. Interesting. 🤔

petelomax said...

If multiple threads are calling (eg) [s]printf(), and that was using a common shared "" constant, they c/would stomp all over each other's reference counts, so using repeat(' ',0) instead of "" creates a new private thread-specific (and in fact call-specific) string, obviously with a private reference count that no other thread can possibly access.

The only "detriment" to using this method for all empty strings would be the footprint size of the app in memory, right? Since it's not sharing the reference, it's making more, thus increasing (by a fraction, no doubt) the app's hold on the available RAM.

Again, just asking for curiosity/knowledge sake!

Thank you!

new topic     » goto parent     » topic index » view message » categorize

5. Re: [Phix] Question About Assignment

euphoric said...

footprint size of the app in memory, ... increasing (by a fraction, no doubt) the app's hold on the available RAM.

Maybe if you have 50 million of them, at 88 bytes per (on 64 bit, 48 bytes per on 32 bit) then that could chew up 4GB, so a more reasonable 1 million is about 2% and the cases you found would in my worst case estimate (seriously, just now I really did do the math) be about 0.0002%

new topic     » goto parent     » topic index » view message » categorize

6. Re: [Phix] Question About Assignment

petelomax said...

Thread safety. If multiple threads are calling (eg) [s]printf(), and that was using a common shared "" constant, they c/would stomp all over each other's reference counts, so using repeat(' ',0) instead of "" creates a new private thread-specific (and in fact call-specific) string, obviously with a private reference count that no other thread can possibly access.

I was under the impression that ....

Specifying the variable or constant in a function's calling syntax function fu(object bar) made bar specific to the calling instance.

Or specifying a new instance of a type object fu = 1 did not point to any shared instances of fu or 1.

Or maybe i read wrong what you said. Are you indeed saying that if procedure1 and procedure2 call function8, procedure1 and procedure2 are inadvertently sharing data inside function8? Because i thought to share data procedure1 and 2 needed to use the same variables from a level one step higher.

This seems at odds with the rules for named loops. If i do for testloop1 = 1 to 10 do, i can expect nothing anywhere can alter testloop1 while the loop is in force?

Slightly related: does the same hold for OE's tasks?

Slightly related also: wasn't this solved in some degree by scoping?

Considered advertising by some: Mirc makes everything freaking global, but it has a feature OE/Phix don't exactly have: i can pass a variable to a function that becomes part of each variable's name within that function, and the other calling procedures cannot know that variable's name or contents (unless they scan the variable list). I use this (for instance) for client/servers of http, appending the destination ip address (and etc) to the name of the socket.

Kat

new topic     » goto parent     » topic index » view message » categorize

7. Re: [Phix] Question About Assignment

katsmeow said...

specific to the calling instance.

That is precisely what reference counts implement: routines are passed references to the same data, but if the
reference count is >1 then attempts to modify it must first clone it, which is what copy-on-write semantics means.
However the reference counts themselves, which your typical hll code cannot (easily) see, are effectively shared.
Integers are not reference counted, but floating-point values and of course strings and sequences are.

Remember: there are exponential performance gains from shared reference counts in the same thread, all this
is only important for programs that actually invoke create_thread(), except for (as being discussed) some minor
precautionary steps bleeding into single thread cases, which I claim are pretty insignificant.

katsmeow said...

Slightly related: does the same hold for OE's tasks?

Technically yes, but since tasks will not and in fact absolutely cannot possibly inc/dec refcounts at the same time, not an issue.

new topic     » goto parent     » topic index » view message » categorize

8. Re: [Phix] Question About Assignment

petelomax said...
euphoric said...

footprint size of the app in memory, ... increasing (by a fraction, no doubt) the app's hold on the available RAM.

...the cases you found would... be about 0.0002%

Well, I figuratively figured, and you literally figured! grin

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu