On 02.07.2008, at 14:29, Werner Coetzee wrote:


Hi

Can anyone explain why gwthread is using the poll function to sleep (using milliseconds as timeout), and not maybe the select function (using microseconds as timeout)?


Kannel can use poll or select. It's a platform specific decision by ./ configure as not all have poll as far as I remember. Select has an issue if you have a lot of file descriptors open as it uses an array of many fd's. poll is much smarter there.

The reason why kannel uses poll on a pipe to sleep is for the simple reason that a thread can be woken up before the sleep time expires by sending a byte to the pipe.

We have the requirement to be able to sleep for less than a millisecond, which the current gwthread_sleep can't provide.

If its for pure sleeping of such small time amounts, you might consult your operating system's documentation. maybe usleep() or nanosleep() is better for such cases. However be aware that if you sleep such small amounts, accuracy can become an issue. Unix kernels are not real time kernels.

usleep() on MacOS X says:

        DESCRIPTION
The usleep() function suspends execution of the calling thread until either useconds microseconds have elapsed or a signal is deliv- ered to the thread whose action is to invoke a signal-catching function or to terminate the thread or process. The actual time slept may be longer, due to system latencies and possible limitations in the timer resolution of the hardware.

This function is implemented, using nanosleep(2), by pausing for useconds microseconds or until a signal occurs. Consequently, in this implementation, sleeping has no effect on the state of process timers and there is no special handling for SIGALRM.






Andreas Fink

Fink Consulting GmbH
Global Networks Schweiz AG
BebbiCell AG
IceCell ehf

---------------------------------------------------------------
Tel: +41-61-6666330 Fax: +41-61-6666331  Mobile: +41-79-2457333
Address: Clarastrasse 3, 4058 Basel, Switzerland
E-Mail:  [EMAIL PROTECTED]
www.finkconsulting.com www.global-networks.ch www.bebbicell.ch
---------------------------------------------------------------
ICQ: 8239353 MSN: [EMAIL PROTECTED] AIM: smsrelay Skype: andreasfink
Yahoo: finkconsulting SMS: +41792457333

http://a-fink.blogspot.com/   A developers view about iPhone SDK





Reply via email to