Test-More / TB2

Test::Builder version 2, the next generation of building testing modules in Perl
Other
1 stars 0 forks source link

Make a version of Streamer::Print which can be shared between threads #197

Closed schwernbot closed 10 years ago

schwernbot commented 10 years ago

From: @schwern Date: Sunday Nov 20, 2011 at 09:35 GMT Orig: https://github.com/Test-More/test-more/issues/232

Perl threads do not support sharing filehandles. All the elements of a shared data structure must be shared. This presents a problem: if we're going to share the TestState and everything in it that includes the Formatter which includes the Streamer which contains a filehandle.

Either Streamer::Print has to put that filehandle outside of itself in a non-shared structure, as suggested here: http://stackoverflow.com/questions/8200159/how-to-share-an-object-which-contains-a-filehandle/8200275#8200275

Or somehow the Streamer is not part of the Formatter. One possibility is to make the Streamer an inside-out object, then all its data can be in unshared structures. http://stackoverflow.com/questions/8200159/how-to-share-an-object-which-contains-a-filehandle/8200621#8200621

Unfortunately thread-safe inside-out objects are difficult in 5.8, but this article about using CLONE might help. http://perlmonks.org/index.pl?node_id=483162

It's ok if changes to the Streamer are not reflected across threads. We can just document not to do that. It doesn't work in stable either.

schwernbot commented 10 years ago

From: @schwern Date: Tuesday Nov 22, 2011 at 06:36 GMT Orig: https://github.com/Test-More/test-more/issues/232#issuecomment-2831021

I have a solution. It's not too bad. http://stackoverflow.com/q/8222822/14660

Two tricks remain. The first is turning that into something which can be applied multiple times to a class (ie. to output_fh and error_fh). That should be a matter of some Mouse->meta->add_attribute.

The second is, ideally, this would only take effect if a thread is created. That involves using the CLONE class method which is nasty work.

Halfway there would be to make it only take effect if threads are enabled.

schwernbot commented 10 years ago

From: @schwern Date: Tuesday Nov 22, 2011 at 08:07 GMT Orig: https://github.com/Test-More/test-more/issues/232#issuecomment-2831556

Well that sucked.