I'm kneedeep in the Shuffler code again, slightly reworking it, fixing some bugs along the way, but also trying to make sure I don't introduce new ones.
The following issue comes up: If I have a struct pike_string with a shared string assigned to it, and I take the value of the str member because I want to access the bytes, how long is this address guaranteed to stay valid?
E.g. I see in file.c that we take the str->str value, then do THREADS_ALLOW() and subsequently call fd_write(). Which seems to imply that as long as the pike_string struct we took the address from is still alive, the address of the string it points will not change, even if other pike threads run in the meantime?
If you hold a reference to the string (using add_ref()) the string is guaranteed to not change it's content.
In principle, strings may change, for instance realloc() can be called when appending to a string, but only if the string has one reference. The code which does append would have an additional reference, which means you are safe to assume the string does not change if you have a reference.
Arne
On 6/18/19 2:19 PM, Stephen R. van den Berg wrote:
I'm kneedeep in the Shuffler code again, slightly reworking it, fixing some bugs along the way, but also trying to make sure I don't introduce new ones.
The following issue comes up: If I have a struct pike_string with a shared string assigned to it, and I take the value of the str member because I want to access the bytes, how long is this address guaranteed to stay valid?
E.g. I see in file.c that we take the str->str value, then do THREADS_ALLOW() and subsequently call fd_write(). Which seems to imply that as long as the pike_string struct we took the address from is still alive, the address of the string it points will not change, even if other pike threads run in the meantime?
pike-devel@lists.lysator.liu.se