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: pthread problem

2002-10-07 Thread Marc Laue

The pth environment is a cooperative model. This means that there is only
one real thread in which all the others are emulated. If one of the
pth-threads no longer needs the cpu, for example because it is put to sleep
for some time, it has to return the control to the pth subsystem which will
continue execution with another waiting pth-thread.

However if you block your real thread by calling a blocking function like
sleep, select, read, etc. the entire program will be halted. This is
why each blocking function has an implementation within the pth library.
These functions are named after their original ones like pth_sleep,
pth_select, and so on.

The replacement functions will handle blocking calls in a special way to
make sure that the other pth-treads will continue to work.

So, if you want to use the pth library you should make sure, you don't block
your program, by always calling the replacement function if available. And
if you have code which will take a long time to execute, you should insert
calls to pth_yield. Otherwise this pth-thread will never return control to
the pth subsystem and this will block the other threads.

About your first testing program: You created a thread and then you start
writing os. Unfortunately you call sleep instead of pth_sleep. Your
main thread will block the entire program each time for one second and
because the pth subsystem is never executed, the other thread will never be
executed as well. The reason why you never saw any . may be because you
called pthread_join instead of pth_join. But this is only a wild guess,
because you posted the pthread version of your test program. However if you
call pth_join the execution of the main thread will be suspended and the pth
subsystem will execute the other thread. This thread is not cooperative as
well because you built the same busy loop which will never return
execution to the pth subsystem but this doesn't matter because your main
thread is already almost done.

The same applies to your second example. If you call select and accept
you can be sure your program blocks and the other threads will never be
executed.

Regards
  Marc


On Fri, Oct 04, 2002 at 12:14:13PM +0200, Terry wrote:
 ive found that out already, but what i was tryin to do was to show
 that somethings wrong with pth's pthread lib.
 
 i tried a few pthreaded programs and they all have problems with pth.
 the prog i pasted here has only unparalleled output, but take this
 one followed for example.
 it wont even open a socket! and this time it doesnt look like 
 a serialization problem does it ? 
 
 what might be wrong with this one ?
 also tested on openbsd and redhat linux.
 
 thanks again in advance,
 terry



msg00356/pgp0.pgp
Description: PGP signature