Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

Re: Please Help - Need ONE HINT - Trying to get

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jason P Sage
Show quoted text 11 lines
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

Reply by email

Marc Santhoff
to Jason P Sage
Jason P Sage wrote 14 lines
>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

Reply by email

Micha Nelissen
to Jason P Sage: Yes. Sleep has been added where appropriate. I didn't know to try Sleep ZERO. That sounds…
Jason P Sage wrote 5 lines
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.

Show quoted text 7 lines
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

Reply by email