Задача: Вычислить математическое выражение по блокам. Каждый блок считать в отдельном потоке. Вот код:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int  a, b, c, d; 
void *S1( void *arg )
 {  
     sum1 = ( b - c ) * 4;
 }
void *S2( void *arg )
 {
     sum2 = ( d + b * c ) * 2;
 }
void *S3( void *arg )
 {
     sum3 = ( d + b) * a ;
 } 
int main( )
 {
   pthread_t thread1, thread2, thread3;
   
   int a, b, c, d; 
   int D1, D2, D3;
   D1 = 1;
   D2 = 2;
   D3 = 3;   
 
   scanf("%d%d%d%d", &a, &b, &c, &d );
   pthread_create( &thread1, NULL, S1, &D1 ); 
   pthread_join( thread1, NULL );  
   pthread_create( &thread2, NULL, S2, &D2 );
   pthread_join( thread2, NULL ); 
   pthread_create( &thread3, NULL, S3, &D3 );
   pthread_join( thread3, NULL ); 
 
   int s = sum1 + sum2 + sum3; 
   printf( "\nSum = %d\n", s );
   return 0;
 } 







