#include:
#include <stdio.h>
#include <pthread.h>
변수 타입 | Value |
---|---|
short | short |
** a** a
a a a
a
sem_init(3) – 지정되지 않은 POSIX 세마포어를 초기화합니다.
sem_open(3) – 지정된 POSIX 세마포어 메모리를 할당하고, 초기화
sem_wait(3) – 세마포어 P 오퍼레이션을 합니다.
sem_trywait(3) – 세마포어는 넌 블록킹의 세마포어 P오퍼레이션을합니다.
sem_post(3) – 세마포어의 V 오퍼레이션을 합니다.
sem_getvalue(3) – 세마포어의 현재 값을 알아봅니다.
sem_destroy(3) – 세마포어를 제거합니다.
sem_close(3) – 지정된 POSIX 세마포어와 연결을 해제합니다.
sem_unlink(3) – 지정된 POSIX 세마포얼르 시스템에서제거합니다
##int sem_init(sem_t *sem, int pshared, unsigned int value);
sem_t *sem_open(const char *name, int oflag);
sem_t *sem_open(const char *name, int oflag, mode_t mode, unsigned int value);
int myint = 3;
##module_param_named(name, value, type, perm);
변수의 값(value)를 내부에 포함 시키고자 할 때 사용
int myintarray[2];
module_param_array(myintarray,int,NULL,0)
int myshortarray[4];
int count;
module_param_array(myshortarray, int, &count, 0);
첨부 코드
- Makefile.c
- module_param.c
module_param.c:
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
//#include <sys/param.h>
int thread_args[3] = { 0,1,2 };
pthread_t threads[3];
void* Thread(void *arg)
{
int i;
for(i=0; i< 10000; i++)
printf("thread %d: %dth ineration \n", *(int*)arg,i);
pthread_exit(0);
}
int main(void *arg)
{
int i;
struct sched_param param;
pthread_t threads[3]; // 스레드 속성 지정을 위한 변수
pthread_attr_t thread_attrs; // 스케줄링 정책 지정을 위한 구조체
for(i=0; i<3; i++)
{
pthread_attr_init(&thread_attrs); // 스레드 속정 초기화
/* 스케줄링 정책 속성을 라운드 로빈으로 설정 */
pthread_attr_setschedpolicy(&thread_attrs, SCHED_RR);
param.sched_priority = 50; // 생성할 스레드의 우선순위 설정
pthread_attr_setschedparam(&thread_attrs, ¶m); // ?
/* 스레드 생성 */
pthread_create(&threads[i],&thread_attrs,(void* (*)(void*))Thread,&thread_args[i]);
}
pthread_exit(0); // 메인 스레드 종료
}