09-20-2008
Creating an array to hold posix thread ids: Only dynamic array works
I am facing a strange error while creating posix threads:
Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output.
Snippet 1
This works:
--------------
int *threadids;
threadids = (int *) malloc (num_threads * sizeof(int));
for(i = 0; i<num_threads; i++)
threadids[i] = i;
for(i=0; i<num_threads; i++)
pthread_create(&threads[i], NULL, pthread_init, &threadids[i]);
.
.
void *pthread_init(void *threadid)
{
int tid;
tid = (int)(*(int *)threadid));
printf("Thread id is %d", tid);
pthread_exit(NULL);
}
Output: Thread id is 0
--------------
Snippet 2
This doesn't work:
--------------
int threadids[num_threads];
for(i = 0; i<num_threads; i++)
threadids[i] = i;
.
.
.
Output: Thread id is 634800
--------------
As you can see, the only difference is in the way the array threadids is declared. But the second snippet gives a garbage value.
I will be glad if someone points out whats going wrong with the first snippet. Thanks.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me
New to scripting
Gundu (3 Replies)
Discussion started by: gundu
3 Replies
2. UNIX for Advanced & Expert Users
Hi,
Do anyone know what's the max size of array (in awk)
can be store before hit any memory issue.
Regards (3 Replies)
Discussion started by: epall
3 Replies
3. Shell Programming and Scripting
Could one of you, please, provide some input regarding my problem below and it is as follows:
I have 2 files that I need to make sure are identical before processing:
First, I sort both files
Second, I do a diff file1 file2 > File 3
This provides me with the difference.
Now, I need to... (6 Replies)
Discussion started by: ddedic
6 Replies
4. Shell Programming and Scripting
Gents,
Below is the Shell script which I am trying to hold a string of array that is passed from a java file. But it is not working . Can any one please help me to by fixing it.
#!/bin/csh/
set copy = ($argv)
echo $copy >> /home/users/bavananr/rrr.log
echo $copy >>... (3 Replies)
Discussion started by: brajesh
3 Replies
5. Shell Programming and Scripting
i want to create an array
the array elements are populated depending upon the number of entries present in a data file
The data file is created dynamically
how to achieve the same
thanks (1 Reply)
Discussion started by: trichyselva
1 Replies
6. Programming
Hi,
I have the following problem: i must allocate a dynamic array from a subroutine which should return such array to main function. The subroutine has already a return parameter so i thought of pass the array as I/O parameter. I tried the following program but it doesn't work (segmentation... (11 Replies)
Discussion started by: littleboyblu
11 Replies
7. Shell Programming and Scripting
Hi,
I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Discussion started by: weak_code-fu
0 Replies
8. Programming
Hi everyone
I am developing an utility.
At some part of it I read directory entries to a dynamic array: struct list
It stores pointers to items: list.entries,
which are structures: struct entry
If a number of files in a directory is greater then number of elements an array was initially... (11 Replies)
Discussion started by: torbium
11 Replies
9. Programming
I put together a C function to add strings to a dynamic array of strings (mostly for educational purpose to explain pointers to my kid). It works, but sometimes one or two strings in the array becomes corrupted. Running example on 64 bit Ubuntu, gcc ver. 4.8.4
Hope my code is self-explanatory:
... (2 Replies)
Discussion started by: migurus
2 Replies
10. Shell Programming and Scripting
Arrays in dash, (POSIX).
Hi gurus...
I am thinking of trying AudioScope.sh in pure POSIX so...
I need an array in dash, I know it is not possible but pseudo-arrays are.
I have two versions that work, the second is an idea from the WWW.
The first is what I would like to use.
There are... (8 Replies)
Discussion started by: wisecracker
8 Replies
LEARN ABOUT DEBIAN
padre::plugin::snippet
Padre::Plugin::Snippet(3pm) User Contributed Perl Documentation Padre::Plugin::Snippet(3pm)
NAME
Padre::Plugin::Snippet - TextMate-like snippets for Padre
SYNOPSIS
cpan Padre::Plugin::Snippet
Then use it via Padre, The Perl IDE.
DESCRIPTION
Once you enable this Plugin under Padre, you'll get TextMate-style TAB triggered snippets for the following:
Perl
Moose
Mouse
MooseX::Declare
Example
For those who don't who this Text mate bloke is, just try to type in Padre something like:
for<tab>
if<tab>
ife<tab>
cfor<tab>
While editing the generated construct, you can type again <TAB>. Your cursor will be moved to the next point needing some attention in the
generated construct.
You can check the available keyword in the yaml files (perl.yml...) shipped with this module.
BUGS
Please report any bugs or feature requests to "bug-padre-plugin-snippet at rt.cpan.org", or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Padre-Plugin-Snippet <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Padre-Plugin-Snippet>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Padre::Plugin::Snippet
You can also look for information at:
o RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Padre-Plugin-Snippet <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Padre-Plugin-Snippet>
o AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Padre-Plugin-Snippet <http://annocpan.org/dist/Padre-Plugin-Snippet>
o CPAN Ratings
http://cpanratings.perl.org/d/Padre-Plugin-Snippet <http://cpanratings.perl.org/d/Padre-Plugin-Snippet>
o Search CPAN
http://search.cpan.org/dist/Padre-Plugin-Snippet/ <http://search.cpan.org/dist/Padre-Plugin-Snippet/>
SEE ALSO
Padre
AUTHORS
Ahmad M. Zawawi <ahmad.zawawi@gmail.com>
CONTRIBUTORS
Adam Kennedy <adamk@cpan.org>
Kevin Dawson <bowtie@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ahmad M. Zawawi
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.14.2 2012-03-27 Padre::Plugin::Snippet(3pm)