Basic Analog Clock [UPDATED]

Share your advanced PureBasic knowledge/code with the community.
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

Got a bit of a thread problem with ur update Electrochrisso. ( they way you have set up the thread with the pause is creating a major crash. )
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Hi Baldrick. Not sure why you get the crash, the only thing that I noticed is the Beep(1000,100) should actually be Beep_(1000,100) as I had a library installed to simulate the API call and did not realize it was not a native PB 402 command.
Could you try this and see. I currently get no crashes on my computers and will do more testing on other systems.
Let me know if you still get crash and I will change it and not use threading and work on a custom timing way.
Thankyou.
PureBasic! Purely the best 8)
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

I had to comment out the first line to compile

---------------------------
PureBasic
---------------------------
Line 5: AppRunning() is not a function, array, macro or linked list
---------------------------
OK
---------------------------

Works when I get rid of it though

Where's that function from?
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

oops I should have noticed that. :oops:
Perhaps that could cause a crash too depending on what libs are installed on certain PB setups this will be deleted from first post now.
It comes from PBOSL_AppRunning for PB 402 to check if an application is already running and not have two same named apps running at the same time.
Thanks pdwyer for noticing that. :)
PureBasic! Purely the best 8)
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

It actually locks up & stops responding forcing me to kill the app, until I take out the pausethread in line 52 of your snippet. Then it runs fine with a really annoying alarm beep :)
I have no idea why the pause is causing problems though. ( It looks really basic to me.. ) - Threadsafe makes no difference either.

Code: Select all

    BeepThread = CreateThread(@AlarmThread(), 0) ;: PauseThread(BeepThread) 
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

Just tried your code with the debugger disabled & it runs ok. It will also run ok with debugger enabled if you put a Delay(1) between the thread creation & pause. :?
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Thanks Baldrick. :)
You get some interesting results. None of this happens on my computers.
Are you running a very fast computer or dual processor. :?:
I will put the Delay(1) in, as this seems to work for your system.
Do you think that the thread safe option be used if I create exe. :?:
PureBasic! Purely the best 8)
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

electrochrisso wrote:Thanks Baldrick. :)
You get some interesting results. None of this happens on my computers.
Are you running a very fast computer or dual processor. :?:
I will put the Delay(1) in, as this seems to work for your system.
Do you think that the thread safe option be used if I create exe. :?:


I am running P4 3Ghz dual processors on my machine if that helps.
I don't really see that threadsafe should be all that neccessary with your little thread as it really isn't doing very much. ( Mind you though I tend to avoid threading wherever possible, especially if 3rd party libs are involved which the threadsafe will generally pick up problems in these libs as soon as you try to run your code. )
You might look at having the thread started by the alarm activation instead of at window startup & using a shared or global variable to run it out when it is reset by the user though. :idea:
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Thanks for the feedback Baldrick. :)
Threading is a fairly advanced feature and the manual does say use with care.
I am probably better off making up my own timing routine for such a simple operation anyway. So I will do that too.
About the hardware question, I was just thinking if the code is being executed too fast it might be trying to pause the thread before it was all set up. So the delay would help in these cases.
The fastest machine I have is a 2.67gig stick of celery (Celeron), not the fastest but does what I need for the moment.
PureBasic! Purely the best 8)
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

You may as well stick with the threading. It is good learning practice & I am sure a time will come when you really do need to run a thread or 2 in an application you are making. So better to get confident with them on something such as this where it really doesn't matter that much, than to get caught later down the track needing them & not having the confidence to have a go at them...
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

I did learn a bit about threading there, but over complicated things and have changed the code now in the first post. See what you think.
It is much more simple now, and thinking about it, it was a bit of a waste using a thread for an alarm that only goes for 10 seconds.
I shall be getting into threads a bit more when I put my Progress Circle to a simple task such as a file copy, now that I have a better idea using threads from the input I have had from good PB coders.
Thanks for your input on this too Baldrick, much appreciated. :)
PureBasic! Purely the best 8)
Post Reply