Created
December 12, 2012 04:58
-
-
Save zerospiel/4264974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #include <sys/wait.h> | |
| #include <sys/ipc.h> | |
| #include <sys/shm.h> | |
| #include <sys/sem.h> | |
| void swap(int[], int, int); | |
| void get_lock(); | |
| void release_lock(); | |
| void print(int[], int); | |
| int partition(int[], int, int, int); | |
| void quicksort(int[], int, int); //todo | |
| //todo main | |
| int* shm_deep; | |
| int max_deep_of_parall; | |
| int sem; | |
| int shm1; | |
| int shm2; | |
| void print(const int array[], const int length) | |
| { | |
| int i; | |
| printf(">"); | |
| for(i = 0; i < length; ++i) | |
| printf(" %d", array[i]); | |
| printf("\n"); | |
| } | |
| void get_lock() | |
| { | |
| struct sembuf operations[1]; | |
| operations[0].sem_num = 0; | |
| operations[0].sem_op = -1; | |
| operations[0].sem_flg = 0; | |
| if (semop(sem_id, operations, 1) == -1) | |
| { | |
| fprintf(stderr, "[%d] ", getpid()); | |
| perror("semop error"); | |
| /* отделяем используемую память */ | |
| shmdt(shm_degree); | |
| /* удаляем сегмент разделяемой памяти */ | |
| shmctl(shm_id1, IPC_RMID, NULL); | |
| shmctl(shm_id2, IPC_RMID, NULL); | |
| semctl(sem_id, 0, IPC_RMID); | |
| exit(1); | |
| } | |
| printf(" %d", *shm_degree); | |
| } | |
| void release_lock() | |
| { | |
| //todo | |
| } | |
| void swap(const int array[], const int left, const int right) | |
| { | |
| int tmp; | |
| tmp = array[left]; | |
| array[left] = array[right]; | |
| array[right] = tmp; | |
| } | |
| int partition(int array[], int left, int right, int pivot_index) | |
| { | |
| int pivot_value = array[pivot_index]; | |
| int store_index = left; | |
| int i; | |
| swap(array, pivot_index, right); | |
| for (i = left; i < right; ++i) | |
| if (array[i] <= pivot_value) | |
| { | |
| swap(array, i, store_index); | |
| ++store_index; | |
| } | |
| swap(array, store_index, right); | |
| return store_index; | |
| } | |
| int main(int argc, char const * argv[]) | |
| { | |
| return 0x0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment