Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: WaitforSingleObject in linux (source code)

Author: Hristo

Date: 22:50:10 04/25/01

Go up one level in this thread


On April 25, 2001 at 18:40:04, Vincent Diepeveen wrote:

... [snip]
>Many thanks.
>
>I don't see how it works, sorry to bother you again!
>
>I do not want to waste 100ms of time for threads.
>
>in my main i'm doing actually not only starting threads but also
>other processes.
>
>Basically those other processes i want to idle:
>
>P1.Main() {
>  allocate shared memory;
>  start other searchprocesses P2..P4;
>  start i/o thread
>
>  thisprocessnumber = P1;
>  Search();
>}
>
>.. iothread() {
>  for(;;) {// this thread doing i/o for all processes
>    now wait for keyboard input and idle when waiting for it;
>    parse_keyboard_input();
>
>    if( relevantkeyboardinput ) { /* so i start to search */
>      // now somehow wakup P1..Pn. what i do now is, is to give it
>      sharedtree->gosearch = true;
>    }
>
>  }
>}

This function will go to sleep until the "return" is pressed.
After this the select will return and you can parse the data.
--- possible implementation to monitor keyboard input ---
#include <stdio.h>


    int fd = 0; // standard input
    fd_set fd_read;
    int fd_ready, nread;
    int bs = 32;
    char buffer[bs+1];

    FD_ZERO(&fd_read);
    FD_SET(fd, &fd_read);
    // last parameter here is the timeout variable pointer
    // when passing 0 we are going to wait forever
    fd_ready = select(1, &fd_read, 0,0,0);
    if (fd_ready > 0) {
        // make sure we read only as much data as it is available
        ioctl (fd, FIONREAD, &nread);
        if (nread > 0){
           nread = (nread > bs)? bs : nread;
           nread = read (fd, buffer, nread);
           buffer[nread] = 0;
        }
    }
--------------------------------------------

In the above example "fd" can be any file descriptor ...

The IPC stuff that you need seems, rather, simple ...
so I might be able to give you an example code tomorrow.
I'm too tired right now. ;-(


hristo


>
>/* now one example is other search */
>
>P2.Search() { /* in main already initialized and synchronized with P1 */
>
>  idle till you get go command and don't waste 100ms or whatever before
>  receiving it as it must wake up DIRECTLY
>}
>
>In short the interesting thing is what to do for P1() to message
>both a thread in the own process to start searching and to also
>message other processes to start searching. Bob says
>i should use Select there somehow, with what function do i message
>this function?
>
>With signal?
>
>Note locking/unlocking i'll manage myself. i've pretty much learned
>to work with locking/unlocking but not with idling yet :)
>
>So interesting to know is how to wait for keyboard input without
>wasting system time while waiting and what
>function to use to message Select in other processes (and one in
>the own process) that it must wake up.
>
>So please read carefully other PROCESSES not threads!!
>It's especially the IPC that worries me :)
>
>>hristo
>>
>>



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.