Threads?

This is a discussion on Threads? within the C++ Programming forums, part of the General Programming Boards category; Here is one such algorithm that requires no special instructions The raw algorithm has been proven correct in an abstract ...

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    3,797
    Here is one such algorithm that requires no special instructions
    The raw algorithm has been proven correct in an abstract machine that doesn't support concurrency the way it works on most machines in real life and assumes strictly ordered reads and writes.

    Consider a machine with multiple real threads of execution that don't share real (hardware) cache: real thread one may cache the shared "ownership" array and mutates real cache which is distinct from the real cache owned by real thread two. Without memory barriers being thrown across the shared array the logic fails in any number of ways.

    In other words, practical implementations in C and C++ for processors with multiple real threads will still need to use primitives that guarantee atomic operations across the real shared array. You can't do that without help from the hardware or operating system.

    On the other hard, the raw algorithm works fine for systems with only one single instruction layer and one real thread of execution.

    If one thread half sets a Number[i] and then another thread calls max() there, the value of Number[i] in the second thread will be set to an UB value.
    This is true, but in practice the "i" is computed so as to be unique to a given thread.

    Soma
    Last edited by phantomotap; 03-18-2012 at 12:46 PM.

  2. #17
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    However, it has been proven correct (though it does require for prerequisites, such as no OOE).
    Hmmm....

    Quote Originally Posted by http://en.wikipedia.org/wiki/Lamport%27s_Bakery_algorithm#Discussion
    The original proof shows that for overlapping reads and writes to the same storage cell only the write must be correct. The read operation can return an arbitrary number.
    In that case, why use a read operation at all? Why not just use rand()? If a write operation uses a value derived from a read operation that can be arbitrary, how is it meaningful whether the write operation is then "correct"?

    I'm not sure what the "Proof" proves either, but if the net result is access to a shared resource whereby a "read operation can return an arbitrary number" then this does not have any practical use value I can think of.
    Last edited by MK27; 03-18-2012 at 12:49 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #18
    Registered User phylene's Avatar
    Join Date
    Mar 2012
    Location
    Seattle
    Posts
    11
    Hey, does tbb have anything over on pthreads? Is it like, better, easier to use, anything like that?

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by phylene View Post
    Hey, does tbb have anything over on pthreads? Is it like, better, easier to use, anything like that?
    As Elysia points out, pthreads is a C API, if that makes a big difference to you.

    TBB looks to me like something built as a higher level API on top of threads, and not a normative threading library, so it depends what you are trying to accomplish. If you want to learn about threading in a traditional sense, I would use something else. But if that doesn't matter and you just want something to provide you with some tools for concurrency, give it a try.

    http://en.wikipedia.org/wiki/Intel_T...uilding_Blocks
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Quote Originally Posted by phylene View Post
    Hey, does tbb have anything over on pthreads? Is it like, better, easier to use, anything like that?
    Of course it is! pthreads is for C, which means it cannot support C++ features.
    tbb and boost takes advantage of C++ features to enable flexibility and control, and cleans up properly so you don't create memory leaks.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threads , how? Portable Threads Library?
    By adderly in forum C++ Programming
    Replies: 3
    Last Post: 12-15-2011, 06:54 AM
  2. Threads
    By Martin Kovac in forum C Programming
    Replies: 2
    Last Post: 05-01-2009, 06:27 AM
  3. Threads on C
    By louis_mine in forum C Programming
    Replies: 4
    Last Post: 06-03-2006, 11:03 PM
  4. a point of threads to create multiple threads
    By v3dant in forum C Programming
    Replies: 3
    Last Post: 10-06-2004, 09:48 AM
  5. threads example
    By Devil Panther in forum Windows Programming
    Replies: 4
    Last Post: 04-24-2004, 06:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21