Sponsored Content
Full Discussion: Threads help
Top Forums Programming Threads help Post 302316547 by smurf2 on Friday 15th of May 2009 11:28:49 AM
Old 05-15-2009
Threads help

Hello! I started studying studying about POSIX Threads a few days ago... so I am a little confused and I would appreciate some help!

I isolated this code... and I wonder if I could use threads in it!

Code:
#include <unistd.h>
#endif

#include <math.h>
//#include "main.h"
#include <sys/time.h>
#include <time.h>


#define TEMPRANGE 100.0
#define ROOMTEMP 0.0

volatile double ***before;
volatile double ***after;

// x-axis
const int cols = 240;
// y-axis
const int rows = 80;
// z-axis
const int faces = 8;


int main(int argc, char** argv){

  char buffer[30];
  struct timeval tv;
  time_t curtime;

  gettimeofday(&tv, NULL); 
  curtime=tv.tv_sec;

  strftime(buffer,30,"%m-%d-%Y  %T.",localtime(&curtime));
  printf("%s%ld\n",buffer,tv.tv_usec);

    int i, j, k;
    before = (volatile double ***) malloc((cols + 2) * sizeof(double **));
    after = (volatile double ***) malloc((cols + 2) * sizeof(double **));

    for(i = 0; i < cols + 2; i++){
        before[i] = (volatile double **) malloc((rows + 2) * sizeof(double *));
        after[i] = (volatile double **) malloc((rows + 2) * sizeof(double *));
    }

    for(i = 0; i < cols + 2; i++){
        for(j = 0; j < rows + 2; j++){
            before[i][j] = (volatile double *) malloc((faces + 2) * sizeof(double));
            after[i][j] = (volatile double *) malloc((faces + 2) * sizeof(double));
        }
    }

    for(i = 0; i < cols + 2; i++){
        for(j = 0; j < rows + 2; j++){
            for(k = 0; k < faces + 2; k++){
                before[i][j][k] = ROOMTEMP;
                after[i][j][k] = ROOMTEMP;
            }
        }
    }

    char buffer1[30];
  time_t curtime1;
  gettimeofday(&tv, NULL); 
  curtime1=tv.tv_sec;

  strftime(buffer1,30,"%m-%d-%Y  %T.",localtime(&curtime1));
  printf("%s%ld\n",buffer1,tv.tv_usec);

}

I was thinking of putting the three for loops in 3 different threads and keep in the main the other code and use pthread_join in main for each one of the 3 threads. I hope you understand my way of thinking... Am I thinking right?
Thank you in advance!
 

9 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

old threads

Neo, if I have an old thread that is a few months old, and a few pages back in the forum it was posted in, is it ok to 'bump' it back to the front? or, would you rather i deleted the old thread, and just create a new one? btw the thread has no replies. (2 Replies)
Discussion started by: norsk hedensk
2 Replies

2. UNIX for Dummies Questions & Answers

threads

i am tring to sort lots of data thats in many columns by just one column but, if I use sort +16 inputfile the column fluctuates because some of the rows have spaces etc within the text, so the end result is just a mess as it jumps around the columns depending whether it has spaces or not ....ie... (2 Replies)
Discussion started by: Gerry405
2 Replies

3. Solaris

threads

Hi all! 1)Is there a way to write a program that will work on both solaris and intel based machines. 2)How can I achive this for a program that creates and synchronizes three threads. Thank you. vij. (3 Replies)
Discussion started by: vijlak
3 Replies

4. UNIX for Advanced & Expert Users

How many threads do I use ?

Hi, I have a program that has two types of threads: 1) Reader threads 2) Worker Threads Readers: Their only job is to read files. They just read data from the files and put them into a buffer. They are obviously I/O intensive. Workers: These are CPU intensive. They do some computation... (5 Replies)
Discussion started by: the_learner
5 Replies

5. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

6. Programming

problem with threads in C

I have problem that if I create for example 100 threads program work correctly but if I define more threads for example 1000 // if I change static int NUM_E from 100 to 1000 than program stop about 350 threads and doesn't continue where should be problem please? #include <pthread.h>... (4 Replies)
Discussion started by: Sevco777
4 Replies

7. Programming

Java Threads

Hi guys, I want to start studding about java threads. but the only book available on the market is "Java Threads" by O'Reilly... (0 Replies)
Discussion started by: majid.merkava
0 Replies

8. What is on Your Mind?

Why not more DEVOPS threads?

Hello all, searching for answers about our upcomming infrastructure in my compagny i was sadden by the fact that in my favorite programming forum there was basicly no threads about devops subjects or continious integration platform. Would be fun to know people workflows in their compagny and... (0 Replies)
Discussion started by: maverick72
0 Replies

9. Post Here to Contact Site Administrators and Moderators

Threads disappeared

Dear admins, it seems that some threads or even users have recently (~ 2 days or so) disappeared. Examples: giuliangiuseppe and greycells. The latter asked me for the solution I provided earlier this week. What happened? Can you help? Regards Rüdiger (10 Replies)
Discussion started by: RudiC
10 Replies
J0(3)							     Linux Programmer's Manual							     J0(3)

NAME
j0, j0f, j0l, j1, j1f, j1l, jn, jnf, jnl, y0, y0f, y0l, y1, y1f, y1l, yn, ynf, ynl - Bessel functions SYNOPSIS
#include <math.h> double j0(double x); double j1(double x); double jn(int n, double x); double y0(double x); double y1(double x); double yn(int n, double x); float j0f(float x); float j1f(float x); float jnf(int n, float x); float y0f(float x); float y1f(float x); float ynf(int n, float x); long double j0l(long double x); long double j1l(long double x); long double jnl(int n, long double x); long double y0l(long double x); long double y1l(long double x); long double ynl(int n, long double x); DESCRIPTION
The j0() and j1() functions return Bessel functions of x of the first kind of orders 0 and 1, respectively. The jn() function returns the Bessel function of x of the first kind of order n. The y0() and y1() functions return Bessel functions of x of the second kind of orders 0 and 1, respectively. The yn() function returns the Bessel function of x of the second kind of order n. For the functions y0(), y1() and yn(), the value of x must be positive. For negative values of x, these functions return -HUGE_VAL. The j0f() etc. and j0l() etc. functions are versions that take and return float and long double values, respectively. CONFORMING TO
The functions returning double conform to SVID 3, BSD 4.3, XPG4, POSIX 1003.1-2001. The other functions exist by analogy, and exist on sev- eral platforms. BUGS
There are errors of up to 2e-16 in the values returned by j0(), j1() and jn() for values of x between -8 and 8. 2002-08-25 J0(3)
All times are GMT -4. The time now is 11:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy