리눅스의 쓰레드들의 스케쥴링에 대해서 궁금합니다.

dalant019의 이미지

첫번째 궁금한 것은... 메인 함수 즉 메인 쓰레드의 우선순위가 궁금합니다. 메인 쓰레드에서 생성된 쓰레드들은 메인 쓰레드보다 우선순위가 낮게 되는지... 책에도 메인 쓰레드에 대해서는 안 나와 있네요.(관련 사이트가 있으면 더 좋을 것 같습니다.) 메인 쓰레드의 우선순위를 바꿀 수 있나요?

아래의 프로그램이 라운드 로빈 방식으로 동작하고 있는지 궁금합니다. 출력 결과를 보면 그런 것 같은데 확신이 안서서요~

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pthread.h>

#include <sys/time.h>
#include <time.h>

int l = 1;
int m = 2;
int n = 3;
int o = 4;
void *run(void *pdata)
{
int r = *(int *)pdata;
while (1)
printf("%d", r);
}

int taskcreate(void* (*start)(void*), void* pArg, void* pData)
{
//int pthread_create(pthread_t * thread, pthread_attr_t *attr, void * (*start_routine)(void *), void * arg);
int nErr = 0;
pthread_t pid;
nErr = pthread_create(&pid, NULL, start, pArg);

return nErr;
}

void *manage(void *pdata)
{
taskcreate(run, (void *)&l, NULL);
taskcreate(run, (void *)&m, NULL);
taskcreate(run, (void *)&n, NULL);
while(1)
{
pirntf("%d", o);
}
}

int main(int argc, char **argv)
{
taskcreate(run, NULL, NULL);
while (1)
printf("m");
}

마지막 가장 궁금한 것인데요... 혹시 쓰레드 마다 다르 타임 슬라이스를 응용에서 결정할 수 있나요? 너무 심한 권한 침법 적인가?

wariua의 이미지

* 코드는 [ code ] 태그를 사용해 주시면 예쁩니다 :)

세 가지 스케줄링 방식(SCHED_OTHER, SCHED_RR, SCHED_FIFO) 중 SCHED_OTHER가 기본값입니다. 즉, pthread_attr_setschedpolicy()pthread_setschedparam() 등의 함수로 policy를 지정해 주지 않으면 pthread 라이브러리의 '나름대로의 기본' 스케줄링 정책을 사용합니다. 위 소스가 RR로 동작하는 것'처럼' 보이는 건 각 스레드가 수행하는 작업의 성격이 비슷(하다 못해 동일)해서 그렇지 싶습니다.

RR(round-robin) 혹은 FIFO(first-in, first-out) 스케줄링 정책으로 동작하는 스레드의 우선순위를 바꾸는 건 pthread_setschedparam()을 이용하실 수 있습니다.

음... 스레드의 timeslice를 직접 지정한다는 건 좀... 거시기 할 듯 합니다. timeslice란 게 스케줄러(리눅스의 경우 user thread 방식이니까, pthread 라이브러리의 스케줄러)가 프로세스/스레드 우선순위 메커니즘을 구현하는 데에 사용하는 유용한 수단인데, 그걸 윗쪽에서 제어하는 건 좀... 예, 말씀 대로 너무 심한 권한 침범 같습니다. 게다가 운영체제에 따라서, 같은 운영체제의 상이한 버전에 따라서, pthread 라이브러리의 상이한 버전에 따라서 사용하는 timeslice의 범위가 다를 수 있다는 문제도 있구요.

$PWD `date`

쎄피로의 이미지

리눅스에서는 훌륭한 커널 개발자 분들이 가장 최적의 slice값을 정해 하드코딩한걸로 기억합니다만, 작은 real-time os들은 직접 변경이 가능합니다. 만약 직접 커널 소스를 변경하신다면 가능한 일이긴합니다.

세상은 넓고, 할 일은 많은데, 난 숨만 쉬고 있니?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.