Hi everyone,
Her is the code I use :
function delay (secs)
local i
i = seconds () + secs
while (seconds () < i)
hb_idlestate ()
end
return (nil)
- CPU usage : 0 to 2 %
- secs : number of seconds to wait.
You can also specify 0.1 for 100 milliseconds
- seconds () : standard clipper function
- Caution : if the function is called at 23:59:59 and the wait is 2
seconds, the function will never exit. So I have added the DATE notion in
the function.
Greatings,
Frans
-----Message d'origine-----
De : [email protected]
[mailto:[email protected]] De la part de smu johnson
Envoyé : vendredi 29 janvier 2010 8:19
À : Users of the Harbour compiler
Objet : Re: [Harbour-users] Telepathy TP_ONTIME / "function calling timer"
alternate implementations?
Alright, I have no freaking clue how to do this properly.
I have found that HB_IDLEADD() will keep calling the <function()> you
specify while it's idle. Problem is, I need it called by millisecond
lengths. This becomes a problem because I don't want to hold up the system
for 5 seconds, simply to count 5 seconds. I need the interrupts to happen
every 5 seconds.
Despite this problem, I tried to experiment. I put a timer inside the
function itself using HB_MILLISECONDS() (hint I got from Viktor S.) But I
am probably going at it the wrong way, as it uses 100% CPU, and still causes
the system to freeze for 5 seconds trying to build up the time to 5
seconds. I'm no expert either, so feel free to call me a fool! I also
tried the Clipper-Tools MILLISEC() function, which also didn't solve the
problem of stalling the system for 5 seconds, and still drilled the CPU to
max the same way my foolish solution did.
PS: The reason I know it's "stalling" is because I am being prompted by a
WAIT command at the end of the program below, and hitting any key has to
wait till the 5 second timer finishes before it quits.
--- code ---
func say()
local now
local interval := 1000
start = HB_MILLISECONDS()
do while (HB_MILLISECONDS() - start <= interval) // kill time loop
end do
? "Here I am!"
// end func
func main()
local nTask
nTask := HB_IDLEADD( {|| say() })
wait
return nil
-----
Thanks for reading!!
Yours frustrated,
smu johnson :)
On Thu, Jan 28, 2010 at 5:28 AM, smu johnson <[email protected]> wrote:
> Sorry, I was calling the wrong function... I was too hasty.
>
>
> On Thu, Jan 28, 2010 at 5:17 AM, smu johnson <[email protected]> wrote:
>
>> It seems that the background func call is what I want, but I can't get it
>> to implement.
>>
>> I grep'd the entire source tree, and found only 3 references:
>>
>> contrib/xhb/bkgtsks.c:extern ULONG hb_backgroundAddFunc( PHB_ITEM
>> pBlock, int nMillisec, BOOL bActive ); /* Adds a codeblock or an
executable
>> array */
>> contrib/xhb/bkgtsks.c:ULONG hb_backgroundAddFunc( PHB_ITEM pBlock, int
>> nMillisec, BOOL bActive )
>> contrib/xhb/bkgtsks.c: hb_retnl( hb_backgroundAddFunc( pBlock,
>>
>> ... When I use it, I get the classic undefined reference to
>> `HB_FUN_HB_BACKGROUNDADDFUNC message.
>>
>> Maybe it is ready yet? *confused*
>>
>> TIA
>>
>>
>> On Thu, Jan 28, 2010 at 3:29 AM, Danny <[email protected]> wrote:
>>
>>> smu johnson ha scritto:
>>>
>>> Hi,
>>>>
>>>> Has anyone found a replacement for Telepathy TP_ONTIME? (it just
allows
>>>> you
>>>> to execute any function you want during any millisecond intervals.
>>>> Unfortunately, the hbtpathy library has left this TP_ONTIME function
>>>> out...
>>>> I e-mailed the author of the Harbour contrib lib, but perhaps he never
>>>> implemented this FUNC because it was not portable.
>>>>
>>>> I wouldn't want to write my own if I didn't have to, as I decided to
ask
>>>> here.
>>>>
>>>> I read some other threads on the mailing list and someone mentioned to
>>>> check
>>>> out another thread on multithreading. It was a bit too high-brow for
>>>> me, as
>>>> well as not really answering this (and the original posters) question.
>>>> In a
>>>> nutshell, I'm looking to implement a simple feature that Telepathy
>>>> provided
>>>> in the DOS days.
>>>>
>>>> As always, any hints highly appreciated. Thank you for reading
>>>>
>>>>
>>>>
>>> I'm not sure about those instructions, but here they are:
>>>
>>> HB_IdleAdd() : Adds a background task for being executed during idle
>>> states
>>> HB_IdleDel() Removes a task from the list of idle tasks.
>>> HB_IdleState() Signals an idle state.
>>> HB_IdleSleepMSec() Queries or changes the default time interval for idle
>>> task processing.
>>>
>>> HB_BackGroundAdd() Adds a new background task.
>>> HB_BackGroundRun() : Enforces execution of one or all background tasks
>>> HB_BackGroundActive() Queries and/or changes the activity of a single
>>> background task.
>>> HB_BackGroundDel() Removes a background task from the internal task
list.
>>> HB_BackGroundReset() Resets the internal counter of background tasks.
>>> HB_BackGroundTime() Queries or changes the wait interval in milliseconds
>>> after which the task is executed.
>>>
>>> StartThread() Starts a new thread.
>>>
>>> HTH
>>> Dan
>>> _______________________________________________
>>> Harbour-users mailing list (attachment size limit: 40KB)
>>> [email protected]
>>> http://lists.harbour-project.org/mailman/listinfo/harbour-users
>>>
>>
>>
>>
>> --
>> smu johnson <[email protected]>
>>
>>
>
>
> --
> smu johnson <[email protected]>
>
>
--
smu johnson <[email protected]>
_______________________________________________
Harbour-users mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour-users
_______________________________________________
Harbour-users mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour-users