Skip to content
Snippets Groups Projects
Commit a7260fec authored by Kim Sunghoo's avatar Kim Sunghoo
Browse files

10일차 수업

parent a099f36a
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#include <pthread.h>
#define FX_Q_NUM 8
#define FX_Q_2 4
#define FX_Q_FVAL 256.0f
#define FX_Q_VAL 256
#if MACHINE_m64
#define fx_mul mul_l
#else
#define fx_mul mul_f
#endif
#define fx_add(a,b) ((a)+(b))
typedef int fixed;
fixed fx_mul_f(fixed a, fixed b)
{
return (fixed)((float) a * (float) b / FX_Q_VAL);
}
fixed fx_mul_i (fixed a, fixed b)
{
return (a*b)>> FX_Q_NUM;
}
fixed fx_mul_2 (fixed a, fixed b)
{
return (a>>FX_Q_2)*(b>>FX_Q_2);
}
fixed fromFloat(float a)
{
return (fixed) (a * FX_Q_FVAL);
}
float toFloat(fixed a)
{
return (float) a / FX_Q_FVAL;
}
fixed fx_div_f(fixed a, fixed b)
{
return (fixed) (FX_Q_FVAL * (float)a / (float) b);
}
fixed fx_div_i(fixed a, fixed b)
{
return (a<<8)/b;
}
fixed fx_div_l(fixed a, fixed b)
{
return (fixed)(((long long) a<<8)/b);
}
void *fx_mul_f_test()
{
int sum = 0;
for (int i=0; i<1000000000; i++)
sum += fx_mul_f(i,i);
return 500;
}
int mul_l_counter=0;
pthread_mutex_t mt_counter = PTHREAD_MUTEX_INITIALIZER;
fixed fx_mul_l (fixed a, fixed b)
{
return (fixed)(((long long) (a) * (long long) b )>> FX_Q_NUM);
}
void *fx_mul_l_test()
{
pthread_mutex_lock(&mt_counter);
mul_l_counter++;
pthread_mutex_unlock(&mt_counter);
int sum = 0;
for (int i=0; i<1000000000; i++)
sum += fx_mul_l(i,i);
return 1000;
}
int main()
{
pthread_t thread;
int result=0;
pthread_create(&thread, NULL, fx_mul_l_test, NULL);
fx_mul_l_test();
printf("Main THREAD : %d\n", result);
// fx_mul_f_test();
pthread_join(thread, (void **) &result);
printf("TWO THREAD END : %d\n", result);
printf("COUNTER: %d\n", mul_l_counter);
}
#include <stdlib.h>
int main()
{
system("ls");
}
#include <stdio.h>
int * f(int a)
{
static int buf[16];
buf[0] = a;
return buf;
}
int main()
{
int a=100;
int b=0;
int *p;
p = f(100);
printf("%d\n", *p);
*p = 200;
printf("%d\n", *p);
printf("%d\n", a/b);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment