Page 2 of 2
Posted: Mon Dec 24, 2007 4:13 pm
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. )
Posted: Tue Dec 25, 2007 12:07 pm
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.
Posted: Tue Dec 25, 2007 12:19 pm
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?
Posted: Tue Dec 25, 2007 12:31 pm
by electrochrisso
oops I should have noticed that.
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.

Posted: Tue Dec 25, 2007 2:40 pm
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)
Posted: Tue Dec 25, 2007 2:55 pm
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.

Posted: Wed Dec 26, 2007 8:25 am
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.

Posted: Wed Dec 26, 2007 12:18 pm
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.

Posted: Thu Dec 27, 2007 3:15 am
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.
Posted: Thu Dec 27, 2007 5:38 am
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...
Posted: Thu Dec 27, 2007 10:48 am
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.
