Re: [fpc-pascal] Please Help - Need ONE HINT - Trying to get

2006-09-16 Thread Jason P Sage
Jason Sage wrote:
 Hi all - and thanks to who ever can respond in advance.
 
  
 
 I have a Server Like App - I need the equivalent of sched_yield

Tried sleep(0); yet ?


 Micha

Yes. Sleep has been added where appropriate. I didn't know to try Sleep
ZERO. That sounds better than my Sleep(10). Thank You for that suggestion.

I was trying to avoid sysutils sleep(0) in linux platform due to the size of
sysutils. The fact I don't know how to make dynamic linking work on linux
yet - (use shared libs versus static) makes my exe's bigger than I would
like. In most of my applications, size isn't an issue - but in one in
particular - it is everything. Using shared linking in linux, which I think
is possible, would make for less overhead for the operating system to invoke
each instance of this (ideally) small as possible application. This small
app is fired often, simultaneously, and load/execute/terminate time is
critical but needs to yield when its not busy. The YIELDING part works.
Thank You. 

On this note, for size reasons, in win 32 I use the Win32 API call that does
the same thing as sysutils sleep. This is what promprted my question - to
call the operating system (in linux I guess its sched_yield) sleep
directly.

In another area around CPU yielding - and multithreading
What I have learned since I wrote this question is that sleep (and
sched_yield) is not an appropriate means to get different threads a
timeslice, which was my impression. I THINK that sleep refers to releasing
or yielding your entire application to other tasks the operating system is
handling. Which means its use should be minimal, and strategic - like when
you application true should release the CPU a bit... or is truly idle.

You see I have been playing with TThread - and I noticed that the most
currently launched thread is the one who stays running - and everything else
in my app stops until it finishes. This leads me to believe I am responsible
for managing what threads runs when - whether timeslices, loop counters
inside the thread - (I ran four iterations - you can suspend me again) ...
or some sort of mechanism. I believe TThread.Syncronize and possibly TThread
Critical Section are going to be my next area of experimentation.

Along this lines I have changed the entire main loop architecture of my
bigger THREADING application - to work similar to how Lazarus makes its
executables or how a windows program works in win32 - I've built a messaging
system - that is a COMMON construct throughout all my classes, so that they
can ALL communicate in a context-less way to the main program - allowing the
main program to respond by suspending, resuming, terminating... etc any/all
of the working threads as it deems correct.

Thank You For Your Response Micha. Any and all help is always appreciated.

Jason P Sage





___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Please Help - Need ONE HINT - Trying to get

2006-09-16 Thread Marc Santhoff
Am Samstag, den 16.09.2006, 09:54 -0400 schrieb Jason P Sage:
 Jason Sage wrote:
  Hi all - and thanks to who ever can respond in advance.
  
   
  
  I have a Server Like App - I need the equivalent of sched_yield
 
 Tried sleep(0); yet ?
 
 
  Micha
 
 Yes. Sleep has been added where appropriate. I didn't know to try Sleep
 ZERO. That sounds better than my Sleep(10). Thank You for that suggestion.

You're maybe looking for fpNanoSleep() on Linux.

HTH,
Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Please Help - Need ONE HINT - Trying to get

2006-09-16 Thread Micha Nelissen
Jason P Sage wrote:
 I was trying to avoid sysutils sleep(0) in linux platform due to the size of
 sysutils. The fact I don't know how to make dynamic linking work on linux
 yet - (use shared libs versus static) makes my exe's bigger than I would
 like. In most of my applications, size isn't an issue - but in one in
 particular - it is everything. Using shared linking in linux, which I think

It's better to help us increase effectiveness of smart linking ;-).

 timeslice, which was my impression. I THINK that sleep refers to releasing
 or yielding your entire application to other tasks the operating system is
 handling. Which means its use should be minimal, and strategic - like when
 you application true should release the CPU a bit... or is truly idle.

I think Sleep is per-thread, not sure though. Anyway, you should never
need Sleep; instead you should use mutexes or similar techniques to
sleep until you need to wake up for calculation or whatever.

 You see I have been playing with TThread - and I noticed that the most
 currently launched thread is the one who stays running - and everything else
 in my app stops until it finishes. This leads me to believe I am responsible

How did you arrive at this conclusion ? It should not be so, the OS will
do the scheduling for you, all threads will get their timeslice.

 or some sort of mechanism. I believe TThread.Syncronize and possibly TThread
 Critical Section are going to be my next area of experimentation.

Critical sections are a sort of mutex indeed, about which I was talking
above.

 Along this lines I have changed the entire main loop architecture of my
 bigger THREADING application - to work similar to how Lazarus makes its
 executables or how a windows program works in win32 - I've built a messaging
 system - that is a COMMON construct throughout all my classes, so that they
 can ALL communicate in a context-less way to the main program - allowing the
 main program to respond by suspending, resuming, terminating... etc any/all
 of the working threads as it deems correct.

Sounds like a good architecture.

Micha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Please Help - Need ONE HINT - Trying to get something like sched_yield with free pascal in linux

2006-09-15 Thread Jason Sage








Hi all  and thanks to who ever can respond in
advance.



I have a Server Like App  I need the equivalent of
sched_yield





I looked in oldlinux unit, and tried the syscallregs , I
tried to use the time structure with it and the syscall_nr_sched_yield (=158)
parameter.



The problem is  in my main processs loop 
it never givers up the CPU  now the really sad thing is in win32 Im
getting much better response using the sleep system call  just a few
milliseconds is all I need, just to allow other things the OS and other spawned
threads might want to get done also.



I was thinking there might be something to signals 
but I dont understand them yet.



Any suggestions would be greatly appreciated.

Jason P Sage










___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Please Help - Need ONE HINT - Trying to get something like sched_yield with free pascal in linux

2006-09-15 Thread Micha Nelissen
Jason Sage wrote:
 Hi all – and thanks to who ever can respond in advance.
 
  
 
 I have a Server Like App – I need the equivalent of sched_yield

Tried sleep(0); yet ?

Micha
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal