Timer Implementation in Pth

2004-06-22 Thread Vinu V

Hi,

My requirement is to have a timer implementation using Pth library.

The call shown below causes the callback func to be called at the specified
timeout:
-
---
main_func()
{
pth_ev = pth_event(PTH_EVENT_FUNC, func, NULL, pth_timeout(0,
50));
pth_wait(pth_ev); /* Thread waits here . it is signalled from
callback - func*/
}

However, the execution of the main_func thread is blocked until it is
signalled which happens when the callback is called.

int func(void * arg)
{
/* In timer callback */
}

I need to have a timer implementation similar to timer_init, timer_add,
timer_settime etcwhere the caller does not get blocked.
Is there a way of doing the same using Pth.?

Kind Regards,
Bhanu Kurpad






DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. 
Before opening attachments please check them for viruses and defects. MindTree 
Consulting Private Limited (MindTree) will not be responsible for any viruses or 
defects or any forwarded attachments emanating either from within MindTree or outside. 
If you have received this message by mistake please notify the sender by return  
e-mail and delete this message from your system. Any unauthorized use or dissemination 
of this message in whole or in part is strictly prohibited.  Please note that e-mails 
are susceptible to change and MindTree shall not be liable for any improper, untimely 
or incomplete transmission.
__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]


Re: Timer Implementation in Pth

2004-06-22 Thread Marc Laue
On Tuesday 22 June 2004 14:22, Vinu V wrote:
 Hi,

 My requirement is to have a timer implementation using Pth library.

 The call shown below causes the callback func to be called at the
 specified timeout:
 ---
-- ---
 main_func()
 {
   pth_ev = pth_event(PTH_EVENT_FUNC, func, NULL, pth_timeout(0,
 50));
   pth_wait(pth_ev); /* Thread waits here . it is signalled from
 callback - func*/
 }

 However, the execution of the main_func thread is blocked until it is
 signalled which happens when the callback is called.

 int func(void * arg)
 {
 /* In timer callback */
 }

 I need to have a timer implementation similar to timer_init, timer_add,
 timer_settime etcwhere the caller does not get blocked.
 Is there a way of doing the same using Pth.?

 Kind Regards,
 Bhanu Kurpad

If I was you I'd spawn a special timer thread. This thread would sleep for a 
while and when it wakes up it would call the callback function and exit or 
sleep again, depending on what kind of behaviour is needed.

Regards
  Marc
__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]


RE: Timer Implementation in Pth

2004-06-22 Thread Naveen K
Wouldn't it be a waste of resource of you were to create same number of
Threads as the Timers required. Instead if we had a functionality within pth
available that would be the best approach or use the underlying Target OS
Timer functionality to get the same functionality. Has there anyone used the
Target OS timer functionality with pth??

Regards,
Naveen

-Original Message-
From: Marc Laue [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 22, 2004 7:56 PM
To: [EMAIL PROTECTED]
Subject: Re: Timer Implementation in Pth


On Tuesday 22 June 2004 14:22, Vinu V wrote:
 Hi,

 My requirement is to have a timer implementation using Pth library.

 The call shown below causes the callback func to be called at the
 specified timeout:
 ---
-- ---
 main_func()
 {
   pth_ev = pth_event(PTH_EVENT_FUNC, func, NULL, pth_timeout(0,
 50));
   pth_wait(pth_ev); /* Thread waits here . it is signalled from
 callback - func*/
 }

 However, the execution of the main_func thread is blocked until it is
 signalled which happens when the callback is called.

 int func(void * arg)
 {
 /* In timer callback */
 }

 I need to have a timer implementation similar to timer_init, timer_add,
 timer_settime etcwhere the caller does not get blocked.
 Is there a way of doing the same using Pth.?

 Kind Regards,
 Bhanu Kurpad

If I was you I'd spawn a special timer thread. This thread would sleep for
a 
while and when it wakes up it would call the callback function and exit or 
sleep again, depending on what kind of behaviour is needed.

Regards
  Marc
__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]


DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. 
Before opening attachments please check them for viruses and defects. MindTree 
Consulting Private Limited (MindTree) will not be responsible for any viruses or 
defects or any forwarded attachments emanating either from within MindTree or outside. 
If you have received this message by mistake please notify the sender by return  
e-mail and delete this message from your system. Any unauthorized use or dissemination 
of this message in whole or in part is strictly prohibited.  Please note that e-mails 
are susceptible to change and MindTree shall not be liable for any improper, untimely 
or incomplete transmission.
__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]


RE: Timer Implementation in Pth

2004-06-22 Thread David Schwartz

 Wouldn't it be a waste of resource of you were to create same number of
 Threads as the Timers required.

Yes, it would.

 Instead if we had a functionality
 within pth
 available that would be the best approach or use the underlying Target OS
 Timer functionality to get the same functionality. Has there
 anyone used the
 Target OS timer functionality with pth??

Just create one thread to handle all the timers. It computes the time until
the next timer fires and does a pthread_cond_timedwait for that amount of
time. Just make sure to signal the condition variable if you add a new timer
that expires before all existing timers. I recommend storing the timers as a
linked list in firing order.

DS


__
GNU Portable Threads (Pth)http://www.gnu.org/software/pth/
Development Site  http://www.ossp.org/pkg/lib/pth/
Distribution Files  ftp://ftp.gnu.org/gnu/pth/
Distribution Snapshots ftp://ftp.ossp.org/pkg/lib/pth/
User Support Mailing List[EMAIL PROTECTED]
Automated List Manager (Majordomo)   [EMAIL PROTECTED]