Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <pthread.h>
- struct arg_struct{
- int
- }
- int inverse(int N, int chisl)
- {
- char buffer[BUF];
- int resbuffer[BUF];
- snprintf(buffer, sizeof(buffer), "%d", chisl);
- for(int i=0; i< strlen(buffer); i++)
- {
- resbuffer[strlen(buffer)-i-1] = abs(N - chisl%10 - 1);
- //printf("OSNOV %d - CIFRA %d - 1 = %d\n",N,chisl%10, N - chisl%10 - 1);
- chisl=chisl/10;
- }
- int inversed=0;
- for(int i=0; i<strlen(buffer); i++) inversed=10*inversed+resbuffer[i];
- //printf("%d", inversed);
- return inversed;
- }
- static void wait_thread(void)
- {
- time_t start_time = time(NULL);
- while (time(NULL) == start_time)
- {
- /* do nothing except chew CPU slices for up to one second. */
- }
- }
- static void *thread_func(void *vptr_args)
- {
- //int convert(int N,int chisl, int length)
- //{
- int result=0;
- for(int i=0; i<length; i++)
- {
- result += chisl%10 * pow(N, i);
- chisl = chisl / 10;
- }
- //}
- int i;
- for (i = 0; i < 20; i++)
- {
- fputs(" b\n", stderr);
- wait_thread();
- }
- return NULL;
- }
- static void *thread_func(void *vptr_args)
- {
- int i;
- for (i = 0; i < 20; i++)
- {
- fputs(" b\n", stderr);
- wait_thread();
- }
- return NULL;
- }
- int main(void)
- {
- int i;
- pthread_t thread1,thread2;
- if (pthread_create(&thread1, NULL, convert, NULL) != 0)
- {
- return EXIT_FAILURE;
- }
- if (pthread_create(&thread2, NULL, inverse, NULL) != 0)
- {
- return EXIT_FAILURE;
- }
- for (i = 0; i < 20; i++)
- {
- puts("a");
- wait_thread();
- }
- if (pthread_join(thread, NULL) != 0)
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement