threads

Stelios Bounanos sb at dial.pipex.com
Mon Mar 25 00:58:01 EET 2002


 >>>>> On Sun, 24 Mar 2002 19:07:04 +0200, usura 
 >>>>> <usura at pathfinder.gr> was runoured to have said:

 > Geia sas,
 > mia aporia pou exei na kanei me programmatismo...
 > estw oti exoume ena programmataki to opoio se kapoio simio
 > xorizere se dio threads, me tin pthread_create.
 > sti sigkekrimeni efarmogi to deytero thread, prepei na exei
 > full priority (de kserw an einai akrivos aytos o sostos oros)
 > diladi 8elw i ektelesi tou na einai oso to dinaton real-time.
 > i sigkekrimeni efarmogi perilambanei arketo disk i/o opote se
 > merika simia to thread "kolaei" epidi o ypologistis diabazei
 > apo to disko. gnwrizei kaneis kapoio tropo wste to thread
 > protereotitas na min diakoptete apo alles diergasies?


Den exw paiksei pote me scheduling & threads alla sthn periptwsh
processes, gia maximum priority kati san to parakatw doyleyei:


----------cut here----------

#include <sys/types.h>
#include <unistd.h>

#ifndef _POSIX_PRIORITY_SCHEDULING
#error "POSIX priority scheduling not available on this system"
#endif

#include <sched.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char** argv)
{
    struct sched_param sp;
    int i, errc = 0;

    if (argc < 2) {
	fprintf(stderr, "Syntax: %s pid [pid ...]\n", *argv);
	exit(EXIT_FAILURE);
    }

    sp.sched_priority = sched_get_priority_max(SCHED_RR);
    for (i = 1; i < argc; i++) {
	if (sched_setscheduler((pid_t)atoi(argv[i]), SCHED_RR, &sp) < 0) {
	    fprintf(stderr, "policy=SCHED_RR, priority=%d: failure for pid %s: %s\n",
		    sp.sched_priority, argv[i], strerror(errno));
	    errc++;
	}
	else
	    fprintf(stderr, "policy=SCHED_RR, priority=%d: success for pid %s\n",
	            sp.sched_priority, argv[i]);

    }

    return errc;
}

----------cut here----------

To parapanw programma setarei real-time scheduling me maximum priority
gia ta processes poy toy dineis, fysika mono an to trekseis san root.
Thelei ligh prosoxh giati tote ayta moirazontai ton epeksergasth mono
metaksy toys. An de blockaroyn pote ('h kanoyn sched_yield()) mallon
yparxei problhma :>
Mia cpu-intensive douleia gia dokimes einai dd if=/dev/urandom
of=/dev/null bs=1024k count=5


Anyway, gia pthreads blepw oti yparxoyn analoga calls:

% apropos pthread | grep sched
pthread_attr_getinheritsched (3thr) - thread creation attributes
pthread_attr_getschedparam (3thr) - thread creation attributes
pthread_attr_getschedpolicy (3thr) - thread creation attributes
pthread_attr_setinheritsched (3thr) - thread creation attributes
pthread_attr_setschedparam (3thr) - thread creation attributes
pthread_attr_setschedpolicy (3thr) - thread creation attributes
pthread_getschedparam (3thr) - control thread scheduling parameters
pthread_setschedparam (3thr) - control thread scheduling parameters

opote an eisai sigoyros oti einai to swsto approach, kalo diabasma.


 > eyxaristw,
 > --Yannis


Rgds,
/-sb.



More information about the Linux-greek-users mailing list