From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 23 03:58:55 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5970516A4CE for ; Fri, 23 Jul 2004 03:58:55 +0000 (GMT) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 126EF43D45 for ; Fri, 23 Jul 2004 03:58:55 +0000 (GMT) (envelope-from freebsd@joelink.net) Received: from [192.168.0.3] (c-24-14-79-34.client.comcast.net[24.14.79.34]) by comcast.net (rwcrmhc12) with ESMTP id <2004072303585401400evedie>; Fri, 23 Jul 2004 03:58:54 +0000 Message-ID: <41008CFB.90506@joelink.net> Date: Thu, 22 Jul 2004 22:58:51 -0500 From: Joseph M Link User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pradeep reddy punnam References: <20040723022324.55446.qmail@web53409.mail.yahoo.com> In-Reply-To: <20040723022324.55446.qmail@web53409.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: regarding timeout/untimeout kernel functions X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2004 03:58:55 -0000 I dont know anything about the kevent timer stuff, so you should probably look into that before re-inventing the wheel. However, you would only need 1 thread to implement this timer functionality. There are a couple data structures you could use, but it would probably be easiest to use a priorityq. You insert each timer event into the priorityq keyed on when it is due to fire. You look at first item in the queue and subtract the current time from it (gettimeofday()) to determine how long to sleep until the next one is ready. If use select, you'll need to create a pipe and select on it to wake up the thread when you insert new timer events. Joe pradeep reddy punnam wrote: > HI joseph , > > i thought of threading with select before , but i belive that if the number of timers to be checked increases the number of the threads to be maintained increses,so the process may become very hevy. what do u think. > > i think ultimatley i am going to use the above thing. > but in the process of my search i came across the timeout kernel function implemenation > but i can not use that ( which i belive very efficient implementation of timers ), which user can not able to use it , so i just want to discuss it . > > thanks > > - pradeep > > Joseph M Link wrote: > > If you're willing to take some precautions, you could run the timer code > with select/usleep in a separate thread. However, since the callbacks > would originate from that thread, you would need mutexes to protect any > data that the function accesses that could also be accessed by the > normal program flow. > > Joe > > pradeep reddy punnam wrote: > > >>HI all, >>i am working on a project , where i came across a situation where i need to execute a function when a timer expires ,exactly similar to functionality of the timeout() kernel function but i need this in userland(application), and the execution of the function is time sensitive, it should be run immediately when timer expires. >> >>i can't be using poll or select for timer becuse those will block the process untill the timer expires.for me the proess should not be blocked. >>and i also thought of taking the service of the timeout function by writing a system call and using signaling mechanism but i think this will become expensive when the number of timers to be checked increeses. >> >>i read the kern_timeout.c code that is very good implentation.with very less expensive. >>but i think user unable to enjoy that service. >> >>i will thankful if somebody can tell if there is any such a service or way provided by os( that i overlooked). >> >>thanks, >> >>-Pradeep >> >> >> >> >> >> >>--------------------------------- >>Do you Yahoo!? >>Vote for the stars of Yahoo!'s next ad campaign! >>_______________________________________________ >>freebsd-hackers@freebsd.org mailing list >>http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >>To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > > > > --------------------------------- > Do you Yahoo!? > Vote for the stars of Yahoo!'s next ad campaign!