questions about threads

Just starting out? Need help? Post your questions and find answers here.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

tinman, I agree. It's one of those areas that gets confused due to informal/ ill-defined definitions, eg, performance, in terms of throughput, is perfectly acceptable to the one client getting serviced by a non-threaded server.

PS: @tinman - I ain't preaching doc :wink: You must have had the pleasure of working on some pretty impressive parallel hardware no?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

dmoc wrote:PS: @tinman - I ain't preaching doc :wink: You must have had the pleasure of working on some pretty impressive parallel hardware no?
Sadly, no :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

That is sad, given the topic. PS: I particularly like the "Fear Kevin" link but can't decide whether you are fan or foe. Related: have you read Steve Grand's book "Creation: life and how to make it"?
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

hmmm... well, i still intend to make something to get threads to share variables in some shape or fashion... but i've been really swamped at work lately, so i haven't gotten a chance to work on it at all...

i thought i'd pop in and leave a message, so people don't peg me as un-reliable

*sigh* being a sys-admin can be demanding at times... and VERY BORING at other times... too bad this week isn't a boring one...
--Aszid--

Making crazy people sane, starting tomorrow.
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

hmm... i thought of another question that i "think" i know the answer to... but i'm not sure... can reading a variable (string or otherwise) from 2 threads at the same time cause problems, or is it only writing to the variable?
--Aszid--

Making crazy people sane, starting tomorrow.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

dmoc wrote:That is sad, given the topic. PS: I particularly like the "Fear Kevin" link but can't decide whether you are fan or foe. Related: have you read Steve Grand's book "Creation: life and how to make it"?
No, I haven't read it (don't have as much time to expand myself as I would like), but I did get quite interested in his work on Creatures. Pretty clever stuff in there.

As for Kevin, I'm just jealous 8)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

aszid wrote:hmm... i thought of another question that i "think" i know the answer to... but i'm not sure... can reading a variable (string or otherwise) from 2 threads at the same time cause problems, or is it only writing to the variable?
Reading variables should be safe, but be careful with strings because it is the string buffer which is not thread safe, not just the string itself.

The library I started has enough in it for you to be able to safely share resources between threads. And there are a couple of examples in the archive.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

wow, time flies when you forget about the examples you were intending to make....

anyhow, i would like some input from people concerning this snippet, it works fine on my work computer, and the threads share the string equally, but i want to have a few more people, with different OS's and configurations to test it out and see if anything weird happens....

Code: Select all

Global a,b,c,text$

Procedure testme(string$)
  Repeat
    Repeat
      If a = 0
        a = 1
        Repeat
          Delay(1)
        Until b = 1
        text$+"bleh "
        c = 1
      EndIf
    Until c = 1
    a = 0
    b = 0
    c = 0
    Delay(1)
  Until Len(text$) > 500
EndProcedure


CreateThread(@testme(),"bleh")
Repeat
  If a = 1 And c = 0
    b = 1
    Delay(1)
  ElseIf a = 0 And c = 0
    text$ + "blah "
    Delay(1)
  EndIf
Until Len(text$) > 500

Debug text$
please let me know if this crashes your computer, or if you get anything but the desired result (the desired result is: "blah bleh blah bleh.....")

thanks in advance
--Aszid--

Making crazy people sane, starting tomorrow.
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

umm... anyone?? it wont like... break your computer or anything... worst case it'll just crash the program.... maybe windows.... (but i doubt it)

*sigh*
--Aszid--

Making crazy people sane, starting tomorrow.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

It works fine on my machine - Win XP (Home), 512MB RAM.

Eric
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Worked great here..

XP Pro + every patch known to man. P4 2.8GHz, 1 gig of RAM.

After I put this 98 box back together I'll test it on that too.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
HarryO
User
User
Posts: 42
Joined: Wed May 07, 2003 4:25 am
Location: Palatine,IL.,USA

Post by HarryO »

aszid,

I tried it and I only get one string with "blah blah blah" and so on.

Was that the results I was suppose to get?

HarryO
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

well, the desired result was "blah bleh blah bleh" but way longer, the key thing i wanted to make sure of is that each thread got access equally to the variables, one thread adds a "blah" the other adds a "bleh"

so if you just got blah's then that means it didn't work right on your comp...

what os are you running?

thanks for testin it out everyone
--Aszid--

Making crazy people sane, starting tomorrow.
HarryO
User
User
Posts: 42
Joined: Wed May 07, 2003 4:25 am
Location: Palatine,IL.,USA

Post by HarryO »

aszid,

I have a win98 se w/256mb mem.

I did get a very long string, but it only had 'blah' repeated in it.

HarryO
Post Reply