Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
||= happens in Perl code, yet it's not thread safe.

You're still not getting it.

  • ||= is thread-safe, just as with any other operation--unless it is applied to a shared variable.

    That's the basic tenet of threads. Everything(*) is thread-safe unless it involves explicitly shared variables. Clear and unambiguous.

    It is the very raison d'etre of ithreads.

  • Any Perl operation applied to any shared variable is not thread-safe unless you take locks.

    That the basic tenet threads::shared. Again, clear and unambiguous.

There is no purpose in documenting the thread-safety of every opcode--or internal operations--because they are all completely covered by those two simple tenets

And that is what sets iThreads apart, and above, any other shared-state concurrency implementation. You use it exactly as if it was non-threaded, with no shared-state, even for the nasties of interpreted language threading--fat variables & closures. Except where you need shared-state, then you mark it explicitly and take the appropriate precautions.

Sure, the implementation could be more efficient--of time and memory. And the user could be given finer-grained control. But for the most part, inventing a model that allows so many pre-threading modules to just work inside threads is a remarkable achievement. Even the majority of non-Pure Perl modules function perfectly within iThreads, and that's truly remarkable, and no accident.

Artur Bergman should be lauded.

(*)For the pedants: External state excluded.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^4: is ||= threadsafe? by BrowserUk
in thread is ||= threadsafe? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found