Slajd8 (27)

Slajd8 (27)




Explicit Threading

np. P0$1X threads (Pthreads), Windows Threads

ttinclude <stdio.h> ttinclude <pthreads.h>

ttdefine NUM_RECTS 100000 ttdefine NUM_THREADS 4

double gArea = 0.0; pthread_mutex_t gLock;

void *threadFunction(void *pArg) { int myNum = *((int *) pArg) ;

double partialHeight = 0.0, lWidth =1.0 / NUM_RECTS, x;

for (int i = myNum; i < NUM_RECTS; i += NUM_THREADS) {

X = (i + 0.5f)    / NUM_RECTS;

partialHeight += 4.0f / (l.Of + x * x);

}

pthread_mutex_lock(SgLock) ;

gArea += partialHeigth * lWidth; pthread_mutex_unlock(&gLock);

>

/* cd. następny slajd */

T2-2 - Modele obliczeń rozproszonych Marek Nowak 8


Wyszukiwarka

Podobne podstrony:
Slajd9 (26) Explicit Threading np. P0S1X łhreads (Pthreads) - cd. /* cd. z poprzedniego slajdu */ vo
57954 Slajd7 (27) Implicit Threadingnp. Open MP, Intel Threading Builaing Blocks (TBB) static long n
» Wątki Programowanie za pomocą biblioteki POSIX threads. Podstawowe operacje: pthread_create,
10 naprężacze 10. THREAD TENSION COMPONENTS 27 28 Ref. No. Part
BEADED AMULET PURSES • PROJECT FIVE 27 To create the fringe. Take the thread out through the top out
f31 12 Insert Files into Project Look in: Thread7 Ul res U] MainFrm.cpp■AammmuM [•*1 StdAfx.cpp Ul
f31 3 Menu Iłem Properties ^ 1 Caption:
f31 9 Insert Files into Project Look in: Thread5 CountArray.cpp res■I_ Ul MainFrm.cpp Ul
fig11 First thread gains ownership. First thread gives up ownership to second thread. Second th
fig15 Semaphore released. One thread resumed, count stillO. Waitfor semaphore. Count 0.
fig4 Main Thread / Prime calculation thread. Procedurę passedto synchronize executes
fig7 Main Thread Message receivedby main thread M ain thre ad waits for calculation thread

więcej podobnych podstron