Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threads::shared and perlthrtut: Update to give example of object sharing #5578

Closed
p5pRT opened this issue Jun 23, 2002 · 4 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Jun 23, 2002

Migrated from rt.perl.org#9720 (status was 'resolved')

Searchable as RT9720$

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2002

From perl58@dev1.ridas.co.uk

Created by scriptyrich@yahoo.co.uk

Having tried to share objects by writing stuff along the lines​:

  my $a : shared = new FOOBAR;

It took a posting to comp.lang.perl.misc before I realised the error of my ways​:

  my $a = new FOOBAR;
  share($a);

I don't think the threads​::shared and perlthrtut docs make this clear enough -
folks coming to ithreads from Java etc are going to finds things a bit odd to
begin with.

SOLUTION​: More examples in the docs please, esp. regarding object sharing. Also
maybe trim down some of the general threading info in perlthrtut with more
focus on perl threads and how to use them idiomatically.

Perl Info

Flags:
    category=docs
    severity=wishlist

Site configuration information for perl v5.8.0:

Configured by root at Sun Jun 16 00:35:43 BST 2002.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.18-6mdk, archname=i686-linux-thread-multi
    uname='linux dev1.ridas.co.uk 2.4.18-6mdk #1 fri mar 15 02:59:08 cet 2002 i686 unknown '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.0:
    /usr/local/perl/devel/5.8/lib/5.8.0/i686-linux-thread-multi
    /usr/local/perl/devel/5.8/lib/5.8.0
    /usr/local/perl/devel/5.8/lib/site_perl/5.8.0/i686-linux-thread-multi
    /usr/local/perl/devel/5.8/lib/site_perl/5.8.0
    /usr/local/perl/devel/5.8/lib/site_perl
    .


Environment for perl v5.8.0:
    HOME=/home/perl58
    LANG=en_GB
    LANGUAGE=en_GB:en
    LC_COLLATE=en_GB
    LC_CTYPE=en_GB
    LC_MESSAGES=en_GB
    LC_MONETARY=en_GB
    LC_NUMERIC=en_GB
    LC_TIME=en_GB
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/perl/devel/5.8/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/games:/usr/local/java/blackdown/j2sdk1.3.1/bin:/home/rich/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Jul 14, 2005

From @schwern

[perl58@​dev1.ridas.co.uk - Sun Jun 23 02​:21​:24 2002]​:

Having tried to share objects by writing stuff along the lines​:

my $a : shared = new FOOBAR;

It took a posting to comp.lang.perl.misc before I realised the error
of my ways​:

my $a = new FOOBAR;
share($a);

I don't think the threads​::shared and perlthrtut docs make this clear
enough -
folks coming to ithreads from Java etc are going to finds things a bit
odd to
begin with.

SOLUTION​: More examples in the docs please, esp. regarding object
sharing. Also
maybe trim down some of the general threading info in perlthrtut with
more
focus on perl threads and how to use them idiomatically.

threads​::shared and perlthrtut still lacks this additional documentation.

@p5pRT
Copy link
Author

p5pRT commented Jul 17, 2005

From @iabyn

On Thu, Jul 14, 2005 at 01​:33​:54AM -0700, Michael G Schwern via RT wrote​:

[perl58@​dev1.ridas.co.uk - Sun Jun 23 02​:21​:24 2002]​:

Having tried to share objects by writing stuff along the lines​:

my $a : shared = new FOOBAR;

It took a posting to comp.lang.perl.misc before I realised the error
of my ways​:

my $a = new FOOBAR;
share($a);

I don't think the threads​::shared and perlthrtut docs make this clear
enough -
folks coming to ithreads from Java etc are going to finds things a bit
odd to
begin with.

SOLUTION​: More examples in the docs please, esp. regarding object
sharing. Also
maybe trim down some of the general threading info in perlthrtut with
more
focus on perl threads and how to use them idiomatically.

threads​::shared and perlthrtut still lacks this additional documentation.

How about this​:

--
"The greatest achievement of the Austrians has been convincing the world
that Hitler was German, and Mozart Austrian."

Change 25161 by davem@​davem-splatty on 2005/07/17 20​:54​:15

  [perl #9720] document what can be assigned to a shared scalar

Affected files ...

... //depot/perl/ext/threads/shared/shared.pm#38 edit

Differences ...

==== //depot/perl/ext/threads/shared/shared.pm#38 (text) ====

@​@​ -53,6 +53,10 @​@​
  use threads​::shared;

  my $var : shared;
+ $var = $scalar_value;
+ $var = $shared_ref_value;
+ $var = &share($simple_unshared_ref_value);
+ $var = &share(new Foo);

  my($scalar, @​array, %hash);
  share($scalar);
@​@​ -101,6 +105,9 @​@​

C<share> will traverse up references exactly I<one> level.
C<share(\$a)> is equivalent to C<share($a)>, while C<share(\\$a)> is not.
+This means that you must create nested shared data structures by first
+creating individual shared leaf notes, then adding them to a shared hash
+or array.

A variable can also be marked as shared at compile time by using the
C<shared> attribute​: C<my $var : shared>.
@​@​ -109,6 +116,20 @​@​
need to use C<&share([])> and C<&share({})> syntax due to problems
with Perl's prototyping.

+The only values that can be assigned to a shared scalar are other scalar
+values, or shared refs, eg
+
+ my $var : shared;
+ $var = 1; # ok
+ $var = &share([]); # ok
+ $var = []; # error
+ $var = A->new; # error
+ $var = &share(A->new); # ok as long as the A object is not nested
+
+Note that it is often not wise to share an object unless the class itself
+has been written to support sharing; for example, an object's destructor
+may get called multiple times, one for each thread's scope exit.
+
=item lock VARIABLE

C<lock> places a lock on a variable until the lock goes out of scope.

@p5pRT p5pRT closed this as completed Oct 16, 2005
@p5pRT
Copy link
Author

p5pRT commented Oct 16, 2005

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant