URL: https://www.opennet.me/cgi-bin/openforum/vsluhboard.cgi
Форум: vsluhforumID9
Нить номер: 969
[ Назад ]

Исходное сообщение
"MultipleWait in POSIX-like environment"

Отправлено CrazyMan , 11-Сен-02 20:38 
Dobroe vremya sutok vsem!
Podskaghite mne, programmeru pod Win32, kak v LINUX-e ili drugoi POSIX-complient systeme realizovat' analog Windows- "WaitForMultipleObjects()", s minimal'num vremenem reaktzii na signali i minimal'nim CPU usage.
Neobhodimo ispol'zovat' POSIX-thread API's & primitives.

Predpologhim nughno oghidat' signala ot 5...6 raznikh semaphorov odnovremenno.
Moghno eto sdelat' v tzikle: non-blocked try-wait i delay. Problema v tom chto esli stavish ochen' malen'kiy delay (< 1 msec) sil'no nagrughaetsya CPU (thread v kotorom delayetsya wait dolghen imet' samiy visokiy prioritet v sisteme, po specificatzii) i ostal'nue thread-i umirayut :-(. Esli delaesh delay bolshoy (> 10 msec), vse khorosho tol'ko vremya reaktzii ne ustraivaet.

Interesno kak eto realizovano v Win32?

Podskaghite, moghet kto-to stalkivalsya s podobnoy problemoy. Budu ochen' priznatelen. Izvinite chto pishu trans-litom, moy komp ne russifitzirovan :-(

THANX IN ANY CASE!


Содержание

Сообщения в этом обсуждении
"RE: MultipleWait in POSIX-like environment"
Отправлено sas , 11-Сен-02 22:43 
Hi,

My comp is also without russian kbd :(

If I understood you right you need something which will work like WaitForMultipleObjects()... For that purpose you can use pthread_join or something like this:

void wait4sem( sem_t *s )
{
    while ( sem_wait( s ) != 0 ) ;
}    

void wait4many_objects( sem_t *s, int how_many )
{
    while ( how_many > 0 ) {
        wait4sem( s );
        how_many--;
    }
}

Also I'm very often using conditional variables for purpose like this.
Please take a look at pthread_cond_wait; pthread_cond_timedwait etc.
May be it will help you. Be aware that to increase chances that thread, which just got wake up get mutex before check condition it is better to call broadcast or signal outside of critical section.


for example:

thread_1
=================================
pthread_mutex_lock( &m );
while ( !your_cond )
    pthread_cond_wait( &cond, &m );
do_something();
pthread_mutex_unlock( &m );

thread_2
=================================
pthread_mutex_lock( &m );
your_cond = true;
pthread_mutex_unlock( &m );
/* signal outside of critical section */
pthread_cond_signal( &cond );

Hope this helps
--- sas


"RE: MultipleWait in POSIX-like environment"
Отправлено CrazyMan , 17-Сен-02 15:19 
Spasibo za otvet!

Sorry, ya navernoe ne sovsem tochno opisal svoyu problemu:
"... Predpologhim nughno oghidat' signala ot 5...6 raznikh semaphorov odnovremenno..."

NO NEOBYAZATEL'NO GHDAT' VSEKH!

T.e. mne nughno viyti iz WAIT-a daghe esli odin iz semaphorov (ne obyazatel'no pervuy) budet prosignalen. POLNAYA SIMULYATZIYA WaitForMultipleObjects() v POSIX-environment.