Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Multithreading Shared Objects


  • Please log in to reply
31 replies to this topic

#13 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 30 January 2011 - 06:54 AM

I've been experimenting with various approaches. This is the latest iteration.
  • 0

#14 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 30 January 2011 - 01:13 PM

Perl has pointers?
  • 0

#15 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 30 January 2011 - 01:15 PM

Some call them references; others call them pointers.
  • 0

#16 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 30 January 2011 - 09:05 PM

There's a difference, but since I primarily deal with C and assembly language I use them almost interchangeably. My bad.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#17 RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 30 January 2011 - 10:00 PM

References are like in JavaScript? ("function a(){ ... } \r\n var f= a; \r\n f();")
  • 0

#18 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 31 January 2011 - 07:59 AM

I tried passing the object itself, instead of a reference, and I still have the same problem.
  • 0

#19 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 31 January 2011 - 09:23 AM

@RhetoricalRuvim: Not really.
@DrTom: You need to use a reference, and you also need to dereference it when making assignments like I showed you above. Can you post the actual code you're having problems with?
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#20 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 31 January 2011 - 11:10 AM

The actual app code is hunders of lines long. Besides that, it's for a police application and has code that should not be disclosed in a public forum. The fundamental problem is in the code I uploaded previously. Did you give it a try?
  • 0

#21 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 31 January 2011 - 11:52 AM

I get this:

"my" variable $midpos masks earlier declaration in same scope at ./Test.pl line
29 (#1)
(W misc) A "my", "our" or "state" variable has been redeclared in the current
scope or statement, effectively eliminating all access to the previous
instance. This is almost always a typographical error. Note that the
earlier variable will still exist until the end of the scope or until
all closure referents to it are destroyed.


Deleting my on line 29 gets rid of the problem. I can't tell you anything more because I don't have Test.txt.

Edited by dargueta, 31 January 2011 - 11:54 AM.
More info

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#22 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 31 January 2011 - 11:56 AM

This is odd. Perhaps I uploaded the wrong code, since I don't have $midpos in my code. I'll remove and re-upload.
  • 0

#23 DrTom

DrTom

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 31 January 2011 - 12:04 PM

Sorry about that. I uploaded the wrong file. I now have the correct file there.
  • 0

#24 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 31 January 2011 - 12:27 PM

Ok, here's your problem:

Original:
printf ("Multithread...\n");
my $tid1 = new threads(\&Child1, $TestPtr);
$tid1->join ();
printf ("Test output to thread 0 = %d\n", ${$TestPtr}->{a});

printf ("\nSingle thread...\n");[B][COLOR="RED"]
Child1 ($TestPtr);
printf ("Test output to thread 0 = %d\n", ${$TestPtr}->{a});
[/COLOR][/B]

Fix:
printf ("Multithread...\n");
my $tid1 = new threads(\&Child1, $TestPtr);
$tid1->join ();
printf ("Test output to thread 0 = %d\n", ${$TestPtr}->{a});

printf ("\nSingle thread...\n");[B][COLOR="RED"]
printf ("Test output to thread 0 = %d\n", ${$TestPtr}->{a});
Child1 ($TestPtr);
[/COLOR][/B]

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download