Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Timing?
#1
I am messing around with threading for something I am working on, and it works except the ouput is slightly garbled. Also depending on what delay I give the teletyping I get different results, all of which are garbled by at least 1 character. For the teletyping, the 2nd and 3rd lines are the threads and the 1st and 4th are regular called routines. Here are the different results I get and the code that I used:

This is what I get when running with Sleep 25
[Image: test25ms6wz.png]

This is what I get when running with Sleep 100
[Image: test100ms4hj.png]

This is what I get when running with Sleep 250
[Image: test250ms4zd.png]

And here is the code:

Code:
declare sub thread1(byval num as integer)
declare sub thread2(byval num as integer)
declare sub teletype(text as string,x,y)

i=threadcreate (@thread1,0)
if (i = 0) then
   print "Error creating thread1"
end if

ii=threadcreate (@thread2,1)
if (ii = 0) then
   print "Error creating thread2"
end if

threadwait(i)
threadwait(ii)

Call teletype ("testing.................",1,1)
Call teletype ("testing again...........",10,1)

sleep
end

sub thread1 (byval num as integer)
   Call teletype ("This is a test...",4,1)
end sub

sub thread2 (byval num as integer)
   Call teletype ("This is another test...",7,1)
end sub

sub teletype (text as string,x,y)
   text_length=len(text)
   for a = 0 to text_length
      temp_text$=mid$(text,a,1)
      Locate x,(y+a-1):Print temp_text$
   sleep 25
   next
end sub
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Reply
#2
Looks to be a glitch in FreeBasic. Maybe it only has one position variable, the one that tells it where it is on the screen.

Where are you putting the SLEEP statement?
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#3
I believe you have to use mutexes for this type of operation. There is a thread about this on the Freebasic forum:

http://www.freebasic.net/forum/viewtopic.php?t=1418
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)