Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: MultiCore issues

  1. #11

    MultiCore issues

    if one of the threads only read an Cardinal i have to protect the acess?

    ps: sorry for the bunch of question, i don't have a Dual Core processor to test ;/
    From brazil (:

    Pascal pownz!

  2. #12

    MultiCore issues

    Quote Originally Posted by arthurprs
    if one of the threads only read an Cardinal i have to protect the acess?

    ps: sorry for the bunch of question, i don't have a Dual Core processor to test ;/
    if it is only reading from a value, then no, you do not need to

  3. #13
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    MultiCore issues

    Quote Originally Posted by Memphis
    Quote Originally Posted by arthurprs
    if one of the threads only read an Cardinal i have to protect the acess?

    ps: sorry for the bunch of question, i don't have a Dual Core processor to test ;/
    if it is only reading from a value, then no, you do not need to
    This is a misleading answer... Mirage summed it up best. If there is the possibility that one thread will read, while another writes to the same variable /record/object, then you should protect ALL access to it accordingly.

    If you have blocks of code that read and write, then protect them with critical sections. If you do more reading than writing, then you may get a performance benefit from using TMultiReadExclusiveWriteSynchronizer which allows simultaneous reads from lots of threads, but will completely block everything when one thread attempts a write.

    You should assume nothing about atomic operations or execution sequence, nothing... except, that if it can go wrong, you can guarantee it will. So, my advice is think carefully about cross thread interactions... where possible keep it to an absolute minimum, and if you can't, try and group variables together into logical blocks that are likely to get updated together and protect the group... this will help keep the overheads down.

    I should also point out, that without running on a dual core or dual CPU machine, you will not find all the potential problems, its impossible as you will only ever have a single thread of execution. To get the real nasty problems you need multiple threads of simultaneous execution... you can only get that on dual core or dual CPU machines.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #14

    MultiCore issues

    Thanks for the answers guys, i have solved the problem with 2 CriticalSections
    From brazil (:

    Pascal pownz!

  5. #15

    MultiCore issues

    Quote Originally Posted by AthenaOfDelphi
    Quote Originally Posted by Memphis
    Quote Originally Posted by arthurprs
    if one of the threads only read an Cardinal i have to protect the acess?

    ps: sorry for the bunch of question, i don't have a Dual Core processor to test ;/
    if it is only reading from a value, then no, you do not need to
    This is a misleading answer...
    it is not misleading at all, if you read correctly.
    if it is only reading
    -MM

  6. #16

    MultiCore issues

    Memphis, it is misleading unless you can ensure atomicity when writing to the variable from somewhere else
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #17

    MultiCore issues

    Quote Originally Posted by JSoftware
    Memphis, it is misleading unless you can ensure atomicity when writing to the variable from somewhere else
    and as he asked, if it is 'only' reading.... now it is not misleading at all, like i said.. IF it is only READING then no, if 2 threads read from the same variable, it is not a problem at all... and in an earlier post i also said to read athenaofdelphis post about IF writing to a variable also ( in which case it would cause a problem ) ... now i rest my case....

  8. #18

    MultiCore issues

    Quote Originally Posted by Memphis
    Quote Originally Posted by JSoftware
    Memphis, it is misleading unless you can ensure atomicity when writing to the variable from somewhere else
    and as he asked, if it is 'only' reading.... now it is not misleading at all, like i said.. IF it is only READING then no, if 2 threads read from the same variable, it is not a problem at all... and in an earlier post i also said to read athenaofdelphis post about IF writing to a variable also ( in which case it would cause a problem ) ... now i rest my case....
    It's not a problem if two threads read from it but that was not what arthurps asked about. He asked if it was ok if one of the threads were reading the variable. That would imply that some other thread will write to it. You can't guarantee that this won't blow up
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  9. #19
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    MultiCore issues

    Before this descends into a total flame war...

    I think we (that is I, JSoftware, Memphis and Mirage) are all pretty much singing from the same song sheet.

    If you can guarantee that a variable will only ever be read by multiple threads, the protection is not required. If however one of those could write to it, then protection is most likely required.

    That I think sums it up nicely.
    :: AthenaOfDelphi :: My Blog :: My Software ::

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •