Thread: Is It Worth Detecting Concurrency?

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Question Is It Worth Detecting Concurrency?

    Hello,

    Just a quick one: I have code that runs multiple threads and does a lot of thread-safe exchanges (in Windows, at the moment). But if the code is running on a system that cannot run threads independently (single core, no hyperthreading), is it worth detecting this condition and including a separate path that exploits this fact?

    I don't know if using thread-safe exchange mechanisms (InterlockedExchangePointer() et. al) has a cost that could be optimised out, is all.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I read the title as "Is it worth detecting currency?" and was prepared to say "If you confuse a dollar $ (USD) for a peso $ (ARS) you'll be sued into oblivion so you are better off letting the user tell you the currency.". Yes, I was disappointed enough that I noted it for sake.

    Now then, if you are using a compiler that transforms API (like `InterlockedExchangePointer') into native processor instructions you should be fine without considering the cost of the operation because the processor will know what it is capable of doing; if you are using a compiler that calls the actual API, from a shared library or something, I can't imagine the cost being more that any other API call.

    So, I'd have to question such a simple notion of "exploiting the facts". If, for example, you currently use a simple algorithm with blocking IO but can use an alternative implantation that uses asynchronous IO doing work while waiting you'll probably find some benefit to working with the knowledge of the environment.

    Obviously the answer depends on what the threaded version takes advantage of versus what the single version may use to its advantage.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Producer Consumer concurrency problem
    By Kurjack in forum C Programming
    Replies: 0
    Last Post: 10-18-2010, 02:21 PM
  2. Maximum concurrency
    By CornedBee in forum Linux Programming
    Replies: 15
    Last Post: 11-23-2007, 06:55 AM
  3. Concurrency documentation
    By subdene in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 02-16-2005, 11:14 AM
  4. concurrency?
    By unregistered in forum C Programming
    Replies: 3
    Last Post: 05-25-2002, 02:11 AM
  5. Is it worth the time....worth the sacrifice?
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-04-2002, 06:33 PM