::: 강좌/소스/문서 :::

강좌/소스/문서 성격에 맞지 않는 광고,비방,질문의 글은 즉시 삭제하며
내용을 복사하여 사용할 경우 반드시 이곳(http://www.howto.pe.kr)을 출처로 명시하여 주세요


Category

  김영대(2003-03-17 02:02:25, Hit : 10776, Vote : 1865
 [Thread] pthread_setschedparam() function

/***************************************************
*--------------------------------------------------
*   Creat  : 2001. 04. 10  (programed by Cori-Young )
*   Site: http://www.byoneself.co.kr
*   Update :
*--------------------------------------------------
*   Compile : cc -o xxx xxx.c -lpthread -lrt
*--------------------------------------------------
* Machine hardware:   sun4u
* OS version:         5.7
* Processor type:     sparc
* Hardware:           SUNW,Ultra-60
***************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <sched.h>

#define _MULTI_THREADED
#define  BUMP_PRIO     1

static void checkResults(char *string, int rc) {

  if (rc) {
    printf("Error on : %s, rc=%d", string, rc);
    exit(EXIT_FAILURE);
  }
  return;
}

int      thePriority = 0;

int showSchedParam(pthread_t thread)
{

  struct sched_param   param;
  int                  policy;
  int                  rc;

  printf("Get scheduling parametersn");

  rc = pthread_getschedparam(thread, &policy, ¶m);
  checkResults("pthread_getschedparam()n", rc);

  printf("The thread scheduling parameters indicate:npriority = %dn", param.sched_priority);

  return param.sched_priority;
}


void *threadfunc(void *parm)
{
  int           rc;

  printf("Inside secondary threadn");

  thePriority = showSchedParam(pthread_self());
  sleep(5);  /* Sleep isn't a very robust way to serialize threads */
  return NULL;
}

int main(int argc, char **argv)
{
  pthread_t             thread;
  int                   rc=0;
  struct sched_param    param;
  int                   policy = SCHED_OTHER;
  int                   theChangedPriority=0;

  printf("Enter Testcase - %sn", argv[0]);
  printf("Create thread using default attributesn");

  rc = pthread_create(&thread, NULL, threadfunc, NULL);
  checkResults("pthread_create()n", rc);

  sleep(2);  /* Sleep isn't a very robust way to serialize threads */

  memset(¶m, 0, sizeof(param));
  
  printf("Set scheduling parameters, prio=%dn",  param.sched_priority);

  rc = pthread_setschedparam(thread, policy, ¶m);
  checkResults("pthread_setschedparam()n", rc);

  /* Let the thread fill in its own last priority */
  theChangedPriority = showSchedParam(thread);

  if (thePriority == theChangedPriority ||

      param.sched_priority != theChangedPriority) {
      printf("The thread didn't get priority set correctly, "
             "first=%d last=%d expected=%dn",
             thePriority, theChangedPriority, param.sched_priority);
      exit(1);
  }

  sleep(5);  /* Sleep isn't a very robust way to serialize threads */
  printf("Main completedn");
  return 0;
}





62   [Unix/Linux] [소스] top for SunOS 5.x (Solaris 2.x)  김영대 2004/02/20 15380 1324
61   [Unix/Linux] [강좌] 인텔 센트리노 무선랜 카드: ndiswrapper  김영대 2004/06/27 12424 2178
60   [Unix/Linux] [POSIX IPC] mq_send() function - 메세지큐  김영대 2003/03/17 12261 1698
59   [Unix/Linux] [System V IPC] shmget() function - 공유메모리  김영대 2003/03/17 11057 1786
58   [Unix/Linux] [Thread] pthread_cond_timedwait() function  김영대 2003/03/17 11008 1859
  [Unix/Linux] [Thread] pthread_setschedparam() function  김영대 2003/03/17 10776 1865
56   [Unix/Linux] [소스] top for System V Release 4, Intel or Sparc CPU  김영대 2004/02/20 10708 1283
55   [Unix/Linux] [System V IPC] shmctl() function - 공유메모리  김영대 2003/03/17 9774 1687
54   [Unix/Linux] [강좌] Apache + MySQL + PHP4 + Zend Optimizer 설치  김영대 2003/04/15 8566 1481
53   [Unix/Linux] [강좌] 웹로그분석을 위한 Webalizer + GDlib + PNGlib + Zlib 설치  김영대 2003/05/04 8419 1510
52   [Unix/Linux] [System V IPC] msgsnd() function - 메세지큐  김영대 2003/03/17 8254 1918
51   [Unix/Linux] [POSIX IPC] mq_receive() function - 메세지큐  김영대 2003/03/17 8162 1814
50   [Unix/Linux] [POSIX IPC] 생산자/소비자 - 세마포어  김영대 2003/03/17 8007 5676
49   [Unix/Linux] [Thread] pthread_cancel() function  김영대 2003/03/17 7987 3787
48   [Unix/Linux] [소스] String 해쉬(hash) 함수  김영대 2003/07/29 7942 1565
47   [Unix/Linux] [Thread] pthread_attr_getschedparam() function  김영대 2003/03/17 6949 8208
46   [Unix/Linux] [System V IPC] msgrcv() function - 메세지큐  김영대 2003/03/17 6926 1692
45   [Unix/Linux] [Thread] 읽고/쓰기  김영대 2003/03/17 6709 1491
44   [Unix/Linux] [System V IPC] semget() function - 세마포어  김영대 2003/03/17 6622 1655
43   [Unix/Linux] [Thread] pthread_cond() function  김영대 2003/03/17 6561 1687

1 [2][3][4]
 

Copyright 1999-2024 Zeroboard / skin by zero