« first day (544 days earlier)      last day (4387 days later) » 

5:00 PM
lol, Andrei Alexandrescu just called Charles a "pussy programmer" :)
 
He programs cats?
 
not quite :)
 
Seen that one coming.
 
5:11 PM
@RMartinhoFernandes Paragraph 9 of 15.4? (With paragraph 12, for good measure.)
 
Oh, fuck. I blew it.
 
@RMartinhoFernandes blew what?
 
@FredOverflow So yes, throw() and noexcept and noexcept(blah) (where blah evaluates to true) have the same semantics.
 
No, not the same. They call different program destroyers.
I blame TVTropes for that mistake of mine.
 
Oh right, I didn't expect std::unexpected again.
4
 
5:16 PM
Y TEH ROBOT HAZ A BUGG?
 
Is there a way to tell SE that I want a chatroom to discuss a question, but it can be deleted after a couple days?
 
Although to be fair std::unexpected defers to std::terminate when all else fails.
 
std::spanish_inquisition
 
std::crusade
 
@MooingDuck Make one?
They get frozen or deleted after some period of inactivity.
> Warning! All control consoles double as Firework Storage Lockers. On detonation of fireworks, please leap dramatically to the floor and feign unconsciousness. — Instruction Manuals for the USS Enterprise
 
5:23 PM
Is that from NoOshaCompliance?
 
It was from TVTropes. But it had a link to the source.
Turned out to be cracked.com.
I hate you.
 
@RMartinhoFernandes I prefer the one where the display next to the button says: "Press to test". Then when you press it, changes to "Test passed. Release to detonate."
Oh, and by the way, Hi everybody!
 
oh hi
 
Lol, at this article.
Worst job of 2012: lumberjack.
 
5:38 PM
Not tired of Herb Sutter yet? (Not Your Father’s) C++
 
How could I call NON-exported functions of DLL?
 
What if I run two C++ executables at once, each from different programs? Does this provide any speedup overall
 
Why would you want to do this? Do they talk to each other?
 
not unless you synchronize them somehow so they aren't both computing the same problem at the same time
 
5:47 PM
Well, if you have a multicore system, each program will probably end up on its own core.
 
but this is just threading, but dumber
 
I want to do this because I have a program that runs a function six times with different parameters, but each one takes hours to run
So I am wondering if I can just make six programs that run the function once each, run em all at once
 
Then do it three times per program, with different parameters.
 
@Luc Online?
 
Sure, if you have an n-core system, make that n programs.
 
5:48 PM
if the results don't depend on each other, then you have an embarassingly parallel problem, which is easy to parallelize
 
@KonradRudolph Yes.
 
I came in here asking how to parallelize earlier and nobody knew
 
that's because you didn't adequately describe your code structure
 
Well, C++ is not the most friendly language when it comes to parallelism.
 
from main() I call a function f() six times
 
5:48 PM
@FredOverflow Depends on the tools. I found PPL and TBB to be very friendly.
 
Just producing 6 different programs is probably the easiest solution to set up.
 
with different numbers
 
that's not adequate
 
@DeadMG Okay, I was talking standard C++, no vendor-specific libraries.
 
@LucDanton Perfect. I just came home and read your comment about is_nothrow_move_constructible … and much to my surprise, this actually evaluates to false.
 
5:49 PM
successful parallelism is about dependencies
do the arguments depend on earlier invocations?
do the results depend on each other?
are there are any internal dependencies?
if each call is totally independent, then you have a program which is trivial to parallelize
 
there are globals, sure
 
then you're fucked
 
but those can be wrapped up in each program
 
step 1 of parallelism: remove globals
 
they are all quite literally independent
 
5:50 PM
@KonradRudolph I run a snapshot of GCC (future 4.8) and same results. I assume it's a deficient implementation of the trait.
 
that's OK
if each function f() is independent, or you can refactor it to make it so, then you have a trivially parallelizable program
 
okay but that's as simple as dragging my globals into f()
what then?
 
you need a threading library
threads are like files and other I/O- they're provided by the OS
you can get various libraries working at various levels of abstraction
you can use your OS library directly, or get a platform-independent abstraction like boost::thread, which would be fine for your case I think
 
@LucDanton OK. Next question: should I file a bug report for this or does this make no sene since the implementation is “work in progress” anyway?
 
anybody know how to link an online mercurial repo to one on my local disk?
 
5:52 PM
if you remove globals, how do threads communicate with each other
 
so I can download the files from the online one
 
@KonradRudolph If you add an explicit specialization of std::is_nothrow_move_constructible for foo (which is a hack I think) that inherits from std::true_type you get the desired behaviour btw.
 
@newprogrammer They don't.
ideally
 
@LucDanton Reassuring :) (no irony implied)
 
i thought the point of multithreading was to split up a job into many tasks
i mean
many threads
 
5:53 PM
meh I am just going to run two programs with three each
 
@newprogrammer Each task needs to be as independent as possible.
serial code is fully dependent- you can only get parallelism by exploiting lack of dependencies
the more dependencies your code has in executing, in terms of data, then the less parallelisable it is
 
ok, let's say i run a thread to communicate with my hard disk, so disk latency doesn't block the rest of my program
 
you can get away with simple dependencies that can be covered by atomics, if you don't use them that much, but more than that is getting quite iffy
 
wouldn't i need a global so the main thread can actually fetch what was retreived from the hard drive
 
@newprogrammer Don't. Your operating system will provide asynchronous I/O.
 
5:55 PM
@KonradRudolph This particular trait is classified as 'missing' in the libstdc++ documentation. I don't know if that's up-to-date for 4.7 (given that the trait is in fact here). Or if there are open issues for it.
 
@Luc … and thanks for the mention of the noexcept operator by the way, I hadn’t known about that
 
@newprogrammer No, you can allocate on the heap for this purpose.
 
@TonyTheLion Hmm, hg pull server_address?
 
Hm, I’m going to search the bug database once I find a minute
 
well you still need like
 
5:56 PM
thread functions can take arguments
 
a global pointer or something
 
nope
 
ok, well if you pass a pointer
 
a thread function tends to be of the form int(*)(void*) and you can put a pointer to heap-allocated data in that void*
 
how does the passing thread know when that data is ready
 
5:56 PM
usually something along the lines of a thread-safe boost::optional<ReturnType>
 
you need a lock, right?
and doesn't that lock need to be global?
 
@newprogrammer You can use atomic operations.
or if you have to use a lock, why not just pass a pair<boost::optional<ReturnType>, Lock>*?
 
there's no reason at all to have such things allocated globally instead of on the heap
 
it's gonna be allocated on the heap
it's just that
i figured, you need at least SOMETHING "global" to communicate between threads
to pass over work done by one thread to another
 
5:58 PM
nope
 
O
I've never used pair<boost::optional<ReturnType>, Lock>* before
 
it's implemented in C++11's threading libraries as std::future<T>
threads don't explicitly "return" anything, but you pass in a pointer to an argument to be mutated
after all
 
I wonder if there should be an std::dinosaur that contains all the obsolete shit.
 
So, uhh, by "future" does it mean something that will be created by the thread you pass it to?
 
global variables are not thread-safe, so how could threading possibly depend on the use of globals?
@newprogrammer It means that a value, of type T, will be computed and put in there at some time in the future by some asynchronous operation.
 
6:01 PM
I thought global variables were thread-safe if you wrapped them in a lock
 
and you can check if it's ready and if so, access the value
noooo
 
which is how i am going about threading so far
 
"thread-safe" != "synchronized"
 
waaat
 
@RMartinhoFernandes ha, I did clone url
 
6:02 PM
every time you synchronize threads, you blow their performance
you turn them into serial code
 
@TonyTheLion Then you're done. I don't understand what your problem is.
 
global variables are a big pit of code structure in single-threaded code, which is enough reason to ban them from any reasonable codebase
but they're a massive pit of incredibly slow programs in multi-threaded code
 
but like
 
@RMartinhoFernandes I've never used Mercurial, was just trying to find out how to do it. Anyways, seems the clone only downloaded files full of garbage, so somethings wrong
 
im just using the global variable wrapped in a lock
like a message queue i believe its called
 
6:03 PM
@newprogrammer Throwing locks at the problem is not a solution. There's nothing that trivial in multithreaded programming
 
each thread will only hold onto the lock for a short time
 
message queues and locks are not at all the same thing
 
do function pointers fall in the category of void*?
 
no worries, found it
 
global variables are really bad in single-threaded code
but they're absolute sin in multi-threaded code
 
6:04 PM
@bamboon No. Function pointers are a different beast from so-called object pointers, which void* is.
 
i use globals in my single-threaded code all the time
is that bad?
 
what's the most upvoted answer on SO? So far I've seen this
 
yes
@IntermediateHacker Eric Lippert has an answer at 1.5k upvotes, and I think the HTML/Regex answer is at 4.5k
@newprogrammer Global variables are one of the worst things you can possibly do, ever.
 
@DeadMG link please.
found it.
4435
A: RegEx match open tags except XHTML self-contained tags

bobinceYou can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool th...

 
6:06 PM
@LucDanton my question is more targeting the style. wheather they are obsolete and shouldn't be used anymore?
 
I wonder how much rep he got for that. O.o
 
@IntermediateHacker Not much. It became community wiki after a few days, and there's a 200 rep cap.
So, ~1000 maybe.
@bamboon Function pointers have at least one limitation that makes them undesirable: they can't do closures.
 
@bamboon Oh! Well they're involved when e.g. you pass in a function to a Standard algorithm. Unlike object pointers they never had the problem of ownership. They're unlikely to blow up in your face, save for the pesky fact that they're nullable. I don't recommend using them as e.g. members or in data structures (whenever storing is involved) though; you either want a generalized functor or e.g. std::function for that.
 
So, is it a bad idea to use threads for asynchrous i/o
 
@newprogrammer Your operating system provides a dedicated subsystem for that
or should do, anyway :P
 
6:09 PM
Boost has an asynchronous I/O library.
 
(Be careful about std::function, people easily get overenthusiastic with it. Although at least no harm comes from that.)
 
and Boost provides a handy-dandy C++ wrapper
 
@newprogrammer It's not the most efficient from the viewpoint of the CPU, but it's often a lot simpler than the alternatives.
 
how do you asynchrous i/o on one thread
without it blocking the thread
 
ask the operating system to do it
 
6:10 PM
@newprogrammer: That requires operating system support
 
let the kernel writer worry about the most efficient way to implement it
it's his problem
 
On Windows it's called overlapped I/O
There's also I/O completion ports
 
oh yaeh
 
what about for cross-platform code
 
and then let the Boost writers worry about the easiest way to call it :P
@newprogrammer Boost.
 
6:11 PM
@newprogrammer: Use a cross-platform library like Boost
They go way out of their way to smooth over platform differences as possible
 
but even so, like let's say you poll() a socket to see if there's data to be read from it
don't you waste CPU cycles polling that socket?
 
@newprogrammer: No, because the OS isn't that stupid
 
alright i have to change things up then
 
erm, when bit shift using >> what does it place on the left of the bit string?
 
@newprogrammer It's not really a "waste". One atomic operation is extremely cheap.
 
6:14 PM
@DeadMG so then how do you communicate between threads generally?
 
@thecoshman 0.
 
@thecoshman It's equivalent to division by powers of two, so zeroes.
 
@LucDanton is it always 0?
 
@newprogrammer Don't is best, and use message passing is better, and use locks only if you absolutely cannot, ever, come up with anything better.
 
hmm...
 
6:14 PM
message passing != message queues?
 
@thecoshman A more complete answer would explain what it does when you do that with signed types, but you shouldn't do that with signed types.
 
@newprogrammer Message queues are used to implement message passing.
 
@newprogrammer: Message queues are an implementation of message passing
 
@thecoshman Unless UB.
 
nah, using unsigned :P
ok, must be doing something else wrong
 
6:15 PM
how do you safely use a message queue
without a lock
 
any way, dinner time :D
 
they are implemented atomically
 
@LucDanton yeah ok, that was what I was thinking with lambdas, std::bind and std::function stuff, just wanted to have that approved
 
@newprogrammer: Use a message queue written by someone smarter than you
 
@thecoshman Just to be safe, char doesn't count as an unsigned type.
 
6:15 PM
:D good advice in silicio
 
they are implemented using "lockless" operations
 
@thecoshman "The right-shift operator causes the bit pattern in the first operand to be shifted to the right by the number of bits specified by the second operand. Bits vacated by the shift operation are zero-filled for unsigned quantities. For signed quantities, the sign bit is propagated into the vacated bit positions. The shift is a logical shift if the left operand is an unsigned quantity; otherwise, it is an arithmetic shift."
 
Note that lockless code is hard to write correctly
 
See? 0, just like I told you.
 
@Insilico As such, always use someone smarter than you's implementation :P
 
6:16 PM
It's hard because it's really easy to write locklesss code that works 99% of the time and fails terribly the other 1% of the time
 
But what if you just hold on to the lock for a REALLY short time?
 
@LucDanton Sorry, didn't notice it hadn't auto-scrolled and that you'd already answered his question
 
@newprogrammer There is nothing as short as a lockless operation.
technically, there is no such thing as "lockless"
but the lock is implemented in hardware on the CPU, and is the fastest you can possibly get.
 
@Collin No worries, making a small joke. I'm just pretending that bitwise operations don't exist for signed types.
 
so such things are called "lockless" even though they don't actually execute with no locks.
 
6:17 PM
@Collin Where is that from?
 
@Collin well then, that's nice and clear, thanks :D
 
Of course, then you run into other issues like false sharing
Especially on multile processor systems
 
yeah, that can be a total hilarity
 
@RMartinhoFernandes As much as a hate to admit: msdn.microsoft.com/en-us/library/336xbhcz(v=vs.100).aspx
 
It's implementation-specific.
 
6:18 PM
If you use a bunch of atomic operations
 
oh woops, implementation defined
 
doesn't that serialize code in the same way that a lock does
 
@Collin: Note the sections called "Microsoft Specific". :-)
 
@newprogrammer Not really.
 
since, like you said, atomic operations are essentially locks at the hardware-level
 
6:19 PM
@newprogrammer: It depends on how stupid your implementation is
 
@Insilico Yeah, I figured the stuff outside the Microsoft Specific section was not Microsoft specific and skipped it
 
well, i don't have much faith in myself, so i expect it to be very, very stupid
 
the difference is mainly that the CPU can automatically re-order atomic operations, for example, and perform instruction-level parallelism
and other very smart things
 
Of course if there's any data sharing, you're going to have to serialize it somehow.
Which is why you don't share data in the first place
 
and secondly, atomic operations are much faster
 
6:20 PM
ok, but let's say like in general, you hold the lock maybe 0.01% of the time
 
If you have to share data, you do so infrequently
 
Much easier to get wrong too.
 
in the time it takes for you to lock the lock, the atomic operation is already done.
then you have to share the data and then unlock the lock again
 
in that case, why deal with the complex atomic operations
 
because atomic operations are vastly faster than locking
you can implement locks in terms of atomic operations, and I assure you, an atomic operation is what's used to lock a lock
 
6:21 PM
@newprogrammer: Because algorithms that use only atomic operations get published in CS journals. :-)
 
locking the lock is 1 atomic operation as it is, and unlocking again is another.
 
Lockless/lockfree programming vs. locks isn't about how long the lock is held. It's about determinism. Lockless algorithms can often be even slower that those using locking -- but (when correct) they guarantee forward progress, where locking algorithms generally don't.
 
plus all the time you expend in between
oh yeah
and lockless algorithms guarantee safety on a level that locks do not
 
and doing i >> 4 actual changes that value of i, it's more like i >>= 4, it dose not just return the result of the bit shift
 
you can't deadlock with an atomic op, for example
 
6:22 PM
But again, lockless algorithms are unbelieveably hard to write
 
atomic ops don't have to be initialized
 
I'm not looking to write high-performance code, just trying to avoid I/O from blocking my main thread for a stupid amount of time
 
The only way to know if a lockless algorithm works is to actually prove it.
 
@newprogrammer Just use boost::asio.
someone with way too much time on their hands already invested way more time and effort than you will ever care to do into solving this problem
just steal their work and be done with it
 
I am completely convinced that lock-free is faster than locks
but it seems harder to use
from MY perspective
 
6:23 PM
@newprogrammer: Not necessarily
 
@thecoshman What? No. i >> 4 is pure.
 
the syntax of locks is so simple and intuitive
 
Again, it depends on how stupid said implementation is
 
@newprogrammer Syntax is irrelevant. The semantics of lockless operations are much superior, and that's what counts.
 
it seems like with lock-free algorithms, even if someone super-smart implemented it, i would sitll have to expend considerable effort into figuring out how they work
 
6:23 PM
and as I already said, if you're writing concurrency code yourself, you're probably doing it wrong. Get a pre-built library solution.
 
Put the blocking code in a separate thread and wrap function objects in POST messages to communicate with the main thread. This way you can avoid data sharing.
 
@newprogrammer The whole point of getting it from someone super-smart is that you don't have to know how it works.
 
Note that concurrent code != thread safe code
You can have very highly concurrent code that is not thread safe
And you can have thread safe code that is not concurrent
 
what's the difference
 
@RMartinhoFernandes as in it is similar to saying i += 4
 
6:25 PM
Having 100 threads working at the same time without any synchronization would be highly concurrent
But not thread safe if they access the same data
 
@thecoshman No, i >> 4 is similar to i + 4 in that respect.
 
@thecoshman no, i >> 4 just shifts i right 4 and returns the result, it doesn't touch i
 
Using locks all over the place of synchronize the data essentially serializes the threads
So you have thread safe, but not concurrent (even with 100 threads)
 
@DeadMG The problem (and he does have a point) is that many (at least current) lock-free implements "leak" enough of the implementation into the interface that even using them isn't always easy. The same is true with some lock-based implementations, but they've been around long enough that most of the bad ones have simply disappeared (though ever year, a new crop of grad students creates more).
 
6:25 PM
¬_¬ god damn it
 
Concurrent and thread-safe is what we want
And that's hard.
 
@JerryCoffin In my opinion, the only C++ threading libraries that are good are PPL and TBB.
most of the rest are way too low-level
and expose way too much
 
it's infinitely easier to parallelise an algorithm when it's "Change for to parallel_for"
 
there we go! it's working!
now to give it some beans!
oh wait... not yet :P
 
6:28 PM
@DeadMG Yes, but at that level, you frequently don't need a parallel library at all. You can leave the code itself alone, and add #pragma omp parallel for, and get about the same effect (but much more portably).
 
eh
I dislike OMP
it's not the same business at all
TBB provides things like parallel_sort, multiple thread mutation safe data structures, and that sort of thing as well
and actor-based concurrency models
#pragma omp parallel for is great, but it's not in the same C++ algorithm and data structure ecosystem
 
@DeadMG Yes, but those aren't just changing for to parallel_for. That's the only thing I was addressing, and OMP does pretty much that.
 
whereas parallel_for_each is exactly in the same vein as for_each and concurrent_vector<T> has begin() and end() and such things
of course not
but it's in the same vein of things
 
I should also point out that TBB/PPL are far from the only libraries to provide things like parallel versions of standard algorithms. In fact, if memory serves the normal libg++ (one of the normal ones for gcc, anyway) has parallel versions of a fair number of standard algorithms, so you can use them without changing code at all -- just recompile with the right switches and you're there.
 
really? I didn't know of any other libraries that operated in that fashion
but good luck using that with Visual C++, say, whereas TBB is compiler-independent
 
6:34 PM
C++ doesn't have veins. It has molten lead coursing through pipes built from the bones of past programmers.
 
that's why I like it- no compiler extensions, just regular C++ library code
 
I'm not going to be prejudiced for or against any of those
all I'm saying is that it's way preferable to deal with parallel_for than boost::thread.
 
@DeadMG It's certainly cleaner and easier -- but you need a lot more than parallel algorithms to make anywhere close to optimal use of many cores for most tasks. From Boost, you're probably looking for something like futures, which are also cleaner and much closer (but definitely not identical) to task-based parallelism.
 
6:39 PM
hmm
I personally think parallel algorithms > futures, but it's perfectly possible that you generally need both
 
@DeadMG Parallel algorithms let you get a little bit of parallelism into basically serial code very easily. It's always a fork/work in parallel/join when that specified work is done, though. Threads let you run arbitrarily long in parallel, doing arbitrary "stuff", and only join when you have something like a data dependency that demands it. The exchange for that is that it's generally a lot harder to get it right.
 
the other thing is that you can fork into N threads, generally
a thread for each job is fixed in the number of jobs
if I parallel_for over an N sized range, then I can spawn as many threads as I like for a reasonable input size, whereas if I spawn one thread to render my game and another to simulate it, then I'm stuck at two cores.
 
@DeadMG You certainly have a point -- most threading code should decouple the task to be completed asynchronously from the thread that runs it. Thread pools are a good thing.
 
You guys are talking parallel to each other
 
thread pools are a great thing
 
6:48 PM
@DeadMG: Does C++ provide a standard thread pool of some kind?
 
AFAIK, no.
but I'm not very up on the C++ Standard thread utilities
 
lol
 
@Insilico Yes -- futures are basically an abstract interface to a thread pool.
 
std::thread_pool was removed before finalization
Boost has a thread pool
 
It remains to be seen if implementations will buy in making std::async with the default launch policy useful.
 
6:50 PM
but you all knew that, and I am Captain Obvious
 
@rubenvb I didn't.
 
@RMartinhoFernandes commented it somewhere on SO
 
@DeadMG you didn't know boost had a thread pool?
 
@MooingDuck Nope.
 
There is no std::thread_pool. It did not become part of the standard. — R. Martinho Fernandes Dec 22 '11 at 2:05
ah crap
 
6:52 PM
@rubenvb I disagree.
 
but as far as I'm concerned, no parallel_for -> no dice
 
@LucDanton wut?
 
@rubenvb What feature of Boost.Thread were you thinking of?
 
I only saw things on the Internetz
I guess what they all were talking about is threadpool.sourceforge.net and not boost related
but there's Boost.Pool, which if it has a diving board, is pretty cool
 
@DeadMG I would tend toward the opposite direction: it would be strongly preferable for the compiler to automatically figure out which for loops can happen in parallel, and do so without having to explicitly request it. There are definitely limits on it, but compilers that could do it to at least some degree have been around since the '70s. We should be moving a few steps beyond that by now.
 
6:54 PM
The one thing that comes close to a thread pool is using Boost.Thread + Boost.Asio. That's a bit overkill.
 
@JerryCoffin Eh. Solving that would be equivalent to solving the Halting Problem.
the compiler can never know if library_call_y(); contains dependencies or not.
 
@DeadMG Solving it in every case, is difficult, and as you say might be impossible. Solving it in a lot of cases isn't (as I said, Cray had compilers that did it reasonably well in the '70s, and they've improved since).
 
I'd expect it to have gotten harder since, not easier
since the scope and complexity of programs has increased massively
and the amount of code dynamically loaded or scripted is also much higher
 
@DeadMG None of that has much effect on figuring out dependencies in a single loop. A larger system has more loops, but a single loop isn't necessarily a lot bigger or more complex. Oh, and Crays weren't used for trivial programs as a rule...
 
sure, but there's a big difference between "non-trivial programs in the 70s" and "programs whose instructions, let alone data, exist several orders of magnitude larger"
 

« first day (544 days earlier)      last day (4387 days later) »