Click here to Skip to main content
15,910,118 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Console Question Pin
Nish Nishant27-Apr-02 6:44
sitebuilderNish Nishant27-Apr-02 6:44 
GeneralRe: Console Question Pin
Brian Delahunty27-Apr-02 6:51
Brian Delahunty27-Apr-02 6:51 
GeneralRe: Console Question Pin
markkuk28-Apr-02 20:30
markkuk28-Apr-02 20:30 
GeneralSaving the printer info like WORD Pin
27-Apr-02 6:08
suss27-Apr-02 6:08 
Generalconst & structs & threads Pin
27-Apr-02 5:37
suss27-Apr-02 5:37 
GeneralRe: const & structs & threads Pin
Neville Franks27-Apr-02 12:47
Neville Franks27-Apr-02 12:47 
GeneralRe: const & structs & threads Pin
Joaquín M López Muñoz28-Apr-02 4:51
Joaquín M López Muñoz28-Apr-02 4:51 
GeneralRe: const & structs & threads Pin
28-Apr-02 10:38
suss28-Apr-02 10:38 
Wish: to have the paramter src to of the function threadedblurfilter const.
--START CODE EXAMPLE--
#include <stdio.h>
#define _REENTRANT
#include <pthread.h>
#include <math.h>
#include "blurfilter.h"
#include "ppmio.h"

typedef struct
{
int xsize;
int ysize;
pixel *src;
pixel *dst;
int radius;
double *weight;
int ystart;
int yend; /*blurfilter calculates including this coordinate.*/
} blurinfo_t;

void *blurfilter(void *);

void threadedblurfilter(const int xsize, const int ysize, pixel *src, pixel *dst
,
const int radius, double *weight, const int nthreads)
{
blurinfo_t *blurinfo = (blurinfo_t *)malloc(nthreads * sizeof(blurinfo_t));
pthread_t *threadId = (pthread_t *)malloc(nthreads * sizeof(pthread_t));
int i, j;
int npixelsperthread = ysize / nthreads;
int ypos = 0;
int breakreached = 0;

for (i = 0; i < nthreads; i++)
{
if ((double)(ysize - ypos) / (double)(nthreads - i) ==
(ysize - ypos) / (nthreads - i) &&
breakreached == 0)
{
breakreached = 1;
npixelsperthread++;
}
blurinfo[i].radius = radius;
blurinfo[i].weight = weight;
blurinfo[i].xsize = xsize;
blurinfo[i].ysize = ysize;
blurinfo[i].src = src;
blurinfo[i].dst = dst;
blurinfo[i].ystart = ypos;
blurinfo[i].yend = blurinfo[i].ystart + npixelsperthread - 1;

pthread_create(&threadId[i], NULL, blurfilter, &blurinfo[i]);

ypos += npixelsperthread;
}


for (j = 0; j < nthreads; j++)
{
pthread_join(threadId[j], NULL);
}

free(threadId);
}

void *blurfilter(void *p)
{
blurinfo_t *blurinfo = (blurinfo_t *)p;
//Lots of heavy calculations.
}

--END CODE EXAMPLE--
Generalchange edit font color Pin
pnpfriend27-Apr-02 4:58
pnpfriend27-Apr-02 4:58 
GeneralRe: change edit font color Pin
shokisingh27-Apr-02 5:20
shokisingh27-Apr-02 5:20 
GeneralRe: change edit font color Pin
moliate27-Apr-02 5:24
moliate27-Apr-02 5:24 
GeneralRe: change edit font color Pin
pnpfriend27-Apr-02 5:56
pnpfriend27-Apr-02 5:56 
GeneralRe: change edit font color Pin
Nish Nishant27-Apr-02 5:55
sitebuilderNish Nishant27-Apr-02 5:55 
GeneralA urgency question Pin
jieg27-Apr-02 4:48
jieg27-Apr-02 4:48 
GeneralRe: A urgency question Pin
Chris Hafey27-Apr-02 8:39
Chris Hafey27-Apr-02 8:39 
GeneralRe: A urgency question Pin
pnpfriend27-Apr-02 10:44
pnpfriend27-Apr-02 10:44 
GeneralRe: A urgency question Pin
pnpfriend27-Apr-02 10:43
pnpfriend27-Apr-02 10:43 
GeneralRe: A urgency question Pin
Neville Franks27-Apr-02 12:48
Neville Franks27-Apr-02 12:48 
GeneralRe: A urgency question Pin
jieg27-Apr-02 17:32
jieg27-Apr-02 17:32 
GeneralRe: A urgency question Pin
Neville Franks27-Apr-02 17:35
Neville Franks27-Apr-02 17:35 
Questionwhy this error message??? Pin
pnpfriend27-Apr-02 3:42
pnpfriend27-Apr-02 3:42 
AnswerRe: why this error message??? Pin
Nish Nishant27-Apr-02 3:53
sitebuilderNish Nishant27-Apr-02 3:53 
GeneralRe: why this error message??? Pin
pnpfriend27-Apr-02 4:51
pnpfriend27-Apr-02 4:51 
GeneralRe: why this error message??? Pin
Nish Nishant27-Apr-02 6:39
sitebuilderNish Nishant27-Apr-02 6:39 
GeneralRe: why this error message??? Pin
pnpfriend27-Apr-02 7:10
pnpfriend27-Apr-02 7:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.