Sponsored Content
Top Forums Programming How can I parallize using pthread Post 302275808 by fpmurphy on Monday 12th of January 2009 08:40:08 AM
Old 01-12-2009
Can you provide the code for Expansion() so we can see what this function is doing?
 

10 More Discussions You Might Find Interesting

1. Programming

More about Pthread

Can someone point to a link where I can get good info about pthread? thanx.. :) (1 Reply)
Discussion started by: jyotipg
1 Replies

2. Programming

pthread

consider if the thread routine returns any void pointer while calling pthread_join, the thread resources are freed and the thread will be terminated when the main thread is exit ,that is my assumption whether it is true how do we find whether the thread is alive or terminated how do we find... (0 Replies)
Discussion started by: MKSRaja
0 Replies

3. Programming

pthread.h

hallo 2 al can anyone pls tell me where and how can i find and install the pthread.h lib ? thx :cool: (2 Replies)
Discussion started by: XinU*
2 Replies

4. Solaris

pthread problem

Hi all! I am working on unix systems.I am programming in c. I have got some problems with pthread.when I use pthread_create to creat a thread it says: (.text+0x3a): undefined reference to `pthread_create'. same is the problm with pthread_kill. Can anyone help me out here. Thanks. vij. (2 Replies)
Discussion started by: vijlak
2 Replies

5. UNIX for Dummies Questions & Answers

a pthread problem

Hello, I run my pthread code on Linux with 4 processors. However, the speed up is only 2 times. The code is about solving equation (G+s(i)C)z(i)=B*us(i), i=1,...,n. Here G,C are m*m matrix, B*us(i) is a m*1 vector and s(i) are n different numbers. I need to solve the equation n times to... (2 Replies)
Discussion started by: mgig
2 Replies

6. Programming

Error with Pthread

problem solved edited, sorry (1 Reply)
Discussion started by: joey
1 Replies

7. UNIX for Advanced & Expert Users

pthread

I am so confused about the user threads and kernel threads.Suppose I created a thread using pthread create call in Linux ,whether it will be a user thread or kernel thread.If it user thread,then how its map to kernel thread. I heard about the M:1,M:N,1:1 mapping methods.Which method linux is... (1 Reply)
Discussion started by: sujith4u87
1 Replies

8. Ubuntu

pthread problem

Hi all, I wrote some code in c, using pthread (I configured the linker and compiler in eclipse IDE first). #include <pthread.h> #include "starter.h" #include "UI.h" Page* MM; Page* Disk; PCB* all_pcb_array; void* display_prompt(void *id){ printf("Hello111\n"); return... (1 Reply)
Discussion started by: elad2109
1 Replies

9. Programming

Help with pthread error

I have written a C code and when i compile it there are 0 warnings and 0 errors, but when i try to run apears: ./client: symbol lookup error: ./client: undefined symbol: pthread_create, version GLIBC_2.1 the part of the code where i have the pthread_creat is: int serverConection(int... (5 Replies)
Discussion started by: SuperStout
5 Replies

10. Programming

pthread()

I have a while loop like so: while (counter (file1)); how can I pass that into a pthread_create()? I was thinking ... while(pthread_create(&path, NULL, counter, file)); is that right? (1 Reply)
Discussion started by: l flipboi l
1 Replies
Moose::Cookbook::Roles::Comparable_CodeReuse(3) 	User Contributed Perl Documentation	   Moose::Cookbook::Roles::Comparable_CodeReuse(3)

NAME
Moose::Cookbook::Roles::Comparable_CodeReuse - Using roles for code reuse VERSION
version 2.0604 SYNOPSIS
package Eq; use Moose::Role; requires 'equal_to'; sub not_equal_to { my ( $self, $other ) = @_; not $self->equal_to($other); } package Comparable; use Moose::Role; with 'Eq'; requires 'compare'; sub equal_to { my ( $self, $other ) = @_; $self->compare($other) == 0; } sub greater_than { my ( $self, $other ) = @_; $self->compare($other) == 1; } sub less_than { my ( $self, $other ) = @_; $self->compare($other) == -1; } sub greater_than_or_equal_to { my ( $self, $other ) = @_; $self->greater_than($other) || $self->equal_to($other); } sub less_than_or_equal_to { my ( $self, $other ) = @_; $self->less_than($other) || $self->equal_to($other); } package Printable; use Moose::Role; requires 'to_string'; package US::Currency; use Moose; with 'Comparable', 'Printable'; has 'amount' => ( is => 'rw', isa => 'Num', default => 0 ); sub compare { my ( $self, $other ) = @_; $self->amount <=> $other->amount; } sub to_string { my $self = shift; sprintf '$%0.2f USD' => $self->amount; } DESCRIPTION
Roles have two primary purposes: as interfaces, and as a means of code reuse. This recipe demonstrates the latter, with roles that define comparison and display code for objects. Let's start with "Eq". First, note that we've replaced "use Moose" with "use Moose::Role". We also have a new sugar function, "requires": requires 'equal_to'; This says that any class which consumes this role must provide an "equal_to" method. It can provide this method directly, or by consuming some other role. The "Eq" role defines its "not_equal_to" method in terms of the required "equal_to" method. This lets us minimize the methods that consuming classes must provide. The next role, "Comparable", builds on the "Eq" role. We include "Eq" in "Comparable" using "with", another new sugar function: with 'Eq'; The "with" function takes a list of roles to consume. In our example, the "Comparable" role provides the "equal_to" method required by "Eq". However, it could opt not to, in which case a class that consumed "Comparable" would have to provide its own "equal_to". In other words, a role can consume another role without providing any required methods. The "Comparable" role requires a method, "compare": requires 'compare'; The "Comparable" role also provides a number of other methods, all of which ultimately rely on "compare". sub equal_to { my ( $self, $other ) = @_; $self->compare($other) == 0; } sub greater_than { my ( $self, $other ) = @_; $self->compare($other) == 1; } sub less_than { my ( $self, $other ) = @_; $self->compare($other) == -1; } sub greater_than_or_equal_to { my ( $self, $other ) = @_; $self->greater_than($other) || $self->equal_to($other); } sub less_than_or_equal_to { my ( $self, $other ) = @_; $self->less_than($other) || $self->equal_to($other); } Finally, we define the "Printable" role. This role exists solely to provide an interface. It has no methods, just a list of required methods. In this case, it just requires a "to_string" method. An interface role is useful because it defines both a method and a name. We know that any class which does this role has a "to_string" method, but we can also assume that this method has the semantics we want. Presumably, in real code we would define those semantics in the documentation for the "Printable" role. (1) Finally, we have the "US::Currency" class which consumes both the "Comparable" and "Printable" roles. with 'Comparable', 'Printable'; It also defines a regular Moose attribute, "amount": has 'amount' => ( is => 'rw', isa => 'Num', default => 0 ); Finally we see the implementation of the methods required by our roles. We have a "compare" method: sub compare { my ( $self, $other ) = @_; $self->amount <=> $other->amount; } By consuming the "Comparable" role and defining this method, we gain the following methods for free: "equal_to", "greater_than", "less_than", "greater_than_or_equal_to" and "less_than_or_equal_to". Then we have our "to_string" method: sub to_string { my $self = shift; sprintf '$%0.2f USD' => $self->amount; } CONCLUSION
Roles can be very powerful. They are a great way of encapsulating reusable behavior, as well as communicating (semantic and interface) information about the methods our classes provide. FOOTNOTES
(1) Consider two classes, "Runner" and "Process", both of which define a "run" method. If we just require that an object implements a "run" method, we still aren't saying anything about what that method actually does. If we require an object that implements the "Executable" role, we're saying something about semantics. AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for details. COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.16.2 2012-09-19 Moose::Cookbook::Roles::Comparable_CodeReuse(3)
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy