Could you spare a few words on what exactly "thread-safe" means?

In the most simple sense, it just means safely usable from mutiple threads. For a more expansive, but generic definition, I cannot do better than wikipedia.

For an answer specific to the use of this particular module, it probably(*) means that it would be safe to use OpenGL in a threaded Perl app, provided that you only call OpenGL from one thread. (This should be safe in as much as every app is a "threaded app", just some of them only use one thread.)

The error message you posted comes about because although you have made no reference to OpenGL within the thread you spawned, threads is trying to clone everything that exists within your main thread at the point of thread creation, into that new thread. As you have use OpenGL;, which is acted upon at BEGIN-time, by the time you create your thread, it already contains stuff from OpenGL. And when threads tried to clone it, for some reason it cannot find the class/module GLUquadricObjPtr.

In theory, you could avoid that problem by delaying the loading of OpenGL until after you created your thread. Something like:

#! perl -slw use strict; use threads; async{ print 'from thread' }->detach; require OpenGL; OpenGL->import( ':all' ); ...

But require followed by import isn't exactly the same as use, in as much as the timing is different. Put it in a BEGIN() block and it is imported prior to your creating the thread, and it gets cloned. Put it in-line with the body of your code, as above, and some or all of the imports are not available (at the appropriate time?) and you get:

c:\test>GLex7.2.pl Bareword "GL_FRONT" not allowed while "strict subs" in use at c:\test\ +GLex7.2.pl line 15. Bareword "GL_AMBIENT" not allowed while "strict subs" in use at c:\tes +t\GLex7.2.pl line 15. Bareword "GL_FRONT" not allowed while "strict subs" in use at c:\test\ +GLex7.2.pl line 16. Bareword "GL_SPECULAR" not allowed while "strict subs" in use at c:\te +st\GLex7.2.pl line 16. Bareword "GL_FRONT" not allowed while "strict subs" in use at c:\test\ +GLex7.2.pl line 17. Bareword "GL_SHININESS" not allowed while "strict subs" in use at c:\t +est\GLex7.2.pl line 17. Bareword "GL_LIGHTING" not allowed while "strict subs" in use at c:\te +st\GLex7.2.pl line 19. Bareword "GL_LIGHT0" not allowed while "strict subs" in use at c:\test +\GLex7.2.pl line 20. Bareword "GL_LEQUAL" not allowed while "strict subs" in use at c:\test +\GLex7.2.pl line 21. Bareword "GL_DEPTH_TEST" not allowed while "strict subs" in use at c:\ +test\GLex7.2.pl line 22. Bareword "GL_FALSE" not allowed while "strict subs" in use at c:\test\ +GLex7.2.pl line 25. Bareword "GLUT_DOUBLE" not allowed while "strict subs" in use at c:\te +st\GLex7.2.pl line 84. Bareword "GLUT_RGBA" not allowed while "strict subs" in use at c:\test +\GLex7.2.pl line 84. Bareword "GLUT_DEPTH" not allowed while "strict subs" in use at c:\tes +t\GLex7.2.pl line 84. Execution of c:\test\GLex7.2.pl aborted due to compilation errors.

Try to bypass that by disabling strict and you get:

c:\test>GLex7.2.pl from thread Argument "GLUT_VOWWLE" isn't numeric in subroutine entry at c:\test\GL +ex7.2.pl line 84. Argument "GL_FRONT" isn't numeric in subroutine entry at c:\test\GLex7 +.2.pl line 15. Argument "GL_AMBIENT" isn't numeric in subroutine entry at c:\test\GLe +x7.2.pl line 15. Unknown material parameter at c:\test\GLex7.2.pl line 15.

Which means that still some of the imports you get from use OpenGL qw[ :all ]; and not available when you do require OpenGL; OpenGL->import( ':all' );. That's pretty frustrating of itself, but the real problem is there is no way to create a thread without it doing the cloning. Now that is really frustrating.

If I ever work out how to do that I'll publish the mechanism, and then many of these pissant frustrations will go away. (Update:rant deleted)

(*)Bottom line: You can probably get away with mixing OpenGL and threads provided:


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Threads + OpenGL act weirdly? by BrowserUk
in thread Threads + OpenGL act weirdly? by Xenofur

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.