Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ele709 lab 3.2
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <pthread.h> struct thread_info { int maxitr; double exec_time; }; typedef struct thread_info thread_info_t; void *func(void *arg) { struct timespec time_1, time_2; double exec_time; thread_info_t *info; int i, maxitr; volatile double a, b, c, count; info = (thread_info_t *)arg; maxitr = info->maxitr; b = 2.3; a = 4.5; exec_time = 0.0; clock_gettime(CLOCK_REALTIME, &time_1); if (count == 0){ for (i = 0; i < maxitr ; i++) { c = a + b; } count = 1; } elseif (count == 1) { for (i = 0; i < maxitr ; i++) { c = a - b; } count = 2; } elseif (count == 2) { for (i = 0; i < maxitr ; i++) { c = a * b; } count = 3; } elseif (count == 3){ for (i = 0; i < maxitr ; i++) { c = a / b; } } else{ printf("A failure, your efforts notwithstanding.\n"); } printf("Computation: %lf\n", c); clock_gettime(CLOCK_REALTIME, &time_2); exec_time = (time_2.tv_sec - time_1.tv_sec); exec_time = exec_time + (time_2.tv_nsec - time_1.tv_nsec)/1.0e9; info->exec_time = exec_time; pthread_exit(NULL); } int main(void) { pthread_t thread1; thread_info_t info1; double maxitr; maxitr = 5.0e8; info1.maxitr = (int)maxitr; if (pthread_create(&thread1, NULL, &func, &info1) != 0) { printf("Error in creating thread 1\n"); exit(1); } pthread_join(thread1, NULL); printf("Exec time for thread1 = %lf sec\n", info1.exec_time); pthread_exit(NULL); main(); }
run
|
edit
|
history
|
help
0
Primer avance de lista enlazadas
Sheldon 9 area none aliens as aliens and farms Lockheed Kelly and lame lead district 9
assignment 3 celina
Array pass effect
acepta el reto 146
gets.c
Prime check
Max successs
Matrices de cadenas con *punteros
Area and Volume coding