« first day (396 days earlier)      last day (4545 days later) » 

2:15 AM
guys
 
hiya all
 
are the close() and shutdown() functions thread-safe?
 
does anyone here know anything about how to link a static lib with a dll?
 
what i mean is, if one thread does accept and other close()/shutdown() at the same time..?
 
i am hoping someone here has some windows prog exp...
 
2:24 AM
linking a static library with a dll is no different from linking it with an exe. the dll gets a copy of the relevant parts of the static library. in the same way as an exe.
 
@Tenev Sockets?
 
well the problem is as follows
 
@RMartinhoFernandes yes
 
The general rule (for pretty much everything) is: if it's not explicitly called out in the documentation, it's not safe for multithreaded use.
 
i have a static lib that i am trying to link with a dll. the dll has my wrapper function which i will export to my exe. the export works fine in the sense that my exe finds it and executes it.
 
2:26 AM
@RMartinhoFernandes fuck it that cant be true
 
problem is that in the dll the wrapper is not able to called the function from the static lib
 
that means we're losing tons of performance
 
:(
because
 
Making things threadsafe hurts performance.
 
2:26 AM
and i am not sure why that is...or how to create that linkage between the static lib and the dll
 
exactly.
 
@Tenev Oh, so you mean that they are documented as safe?
 
no, the opposite...
 
@user245823 if you mean it does not compile, then you don't have a dll
 
@Tenev So, if they're not safe, they're as fast as they can be in a single threaded scenario.
 
2:28 AM
exactly...
 
ok the static lib was created fine. the dll compiles and links fine. the test app that uses the dll compiles and links fine.
 
If you make them threadsafe, you make them slow even if you don't use multiple threads.
@Tenev So, where is the performance loss?
 
there->
 
the problem is that when the exe calls the dll wrapper the function within the wrapper which is calling a function in the static lib is not getting invoked
 
if 1 thread calls accept... and 10 other call close()
 
2:29 AM
and i have no idea why it is not.
 
@user245823 ah, you forgot to call your function. that's a common error. just call it.
 
@Tenev If they're not threadsafe, performance is not relevant, because it just won't work right.
 
well i call the function in the wrapper.
 
@RMartinhoFernandes exactly my point.
 
unless there is some other way to call it. the wrapper is calling the static lib function.
 
2:30 AM
You need to add your own synchronization.
 
@RMartinhoFernandes therefore, we have to be threadsafe, therefore lose performance.
 
@user245823 well here's my thinking: when you say "is not getting called" then that is not an observed fact, but a silly conclusion. run the thing in debugger. check the calls.
 
@Tenev You have to balance the performance gains from using multiple threads with the costs of synchronization.
Sometimes it's worth it, others it isn't.
 
my question actually was
 
You can also design things in a manner that only one thread can close the socket.
 
2:32 AM
well... i had some print to screen calls
 
can i call close() at the same time on different sockets?
 
which i did for example o first used the static lib directly with the exe
it prints certain stmts on screen
then i used the dll wrapper and it did not
 
and also, can i use accept in 1 thread and close on different sockets in many other threads
 
@Tenev Closing different sockets should not pose a problem.
 
even though via dll export app i can see the exported function being called
 
2:33 AM
now that sounds good
 
so my dll wrapper looks something like
 
@user245823 run the thing in a debugger. check the calls.
 
@RMartinhoFernandes would there be a problem if i'm using shutdown(sock)?
@RMartinhoFernandes or, would there be a problem if one thread uses accept() and other is close/shutdown at the same time?
 
@Tenev If that's on the same socket, it's possible.
 
@user245823 also make sure that your DLL uses DLL variant of runtime library. and that everything else uses that same variant.
 
2:35 AM
@RMartinhoFernandes but accept cannot happen on the same socket as close/shutdown
i mean, only 1 thread uses accept() and 10 other use shutdown/close
shutdown would close socket 200, after that accept will use the next available socket (200)
u know... nevermind looks like i'd have to do some hardcore testing
 
if there was mismatch wouldnt' i get some kind of warning or error message?
 
@Tenev Oh, let's see if I understand: one thread calls accept on a socket, and the others close the sockets accept produced?
That should work fine.
 
@RMartinhoFernandes yes
others actually call shutdown(sock) and then close(sock) :)
 
@user245823 no, not necessarily
 
@Tenev Then don't worry. You won't corrupt the kernel's file descriptor table :)
 
2:38 AM
but they would create this symptom i am mentioning i presume?
 
@RMartinhoFernandes thats what i was scared
 
i have been very particular about making sure that i was building all in release version for example. because i think in vs2008 if there are option issues when compiling with different types then it throws warnings at times at least between projects.
i will make it a point to check however just to be sure. i was hoping it was not some weird issue like support.microsoft.com/kb/141459
which again i have been struggling with this issue for a while and seem to have exhausted google/forums research
 
@RMartinhoFernandes now something harder, what about using epoll_wait in 10 threads and epoll_ctl(..EPOLL_CTL_DEL or EPOLL_CTL_ADD) in 10 other threads, every thread has his own (different) epoll file descriptor created with EPOLL_CREATE1? any probs?
 
Oh, I think that's beyond my knowledge. I don't think I have ever used any epoll stuff.
 
damn :(
see, i'm now using epoll... really good thing
but can't read anything abolut multi-threaded epoll
 
2:46 AM
OMG, a three-star programmer: stackoverflow.com/questions/8139440/…
 
leave him
hes a "Lecturer in computer science since 1998. "
is it a coincidence that the C++ standart was invented in 1998 ? :D
 
@user245823 maybe the symptom you're seeing is that output statements don't produce actual output. a debugger is more reliable tool for checking things.
 
yea i am not at work so i cant check right now that i will do tomorrow and see. i mean part of what that function does is also writes to files and outputs it on desktop so i know that there should be other observations that should happen if the function was a success.
in other words could there be an actual issue with how a static lib "links" to a dll project? i am new to vs2008 so i dont know.
 
@RMartinhoFernandes commented on that. sbi is too angry :D
 
@Tenev Woah, he's too angry? And you say he has a "stupid looking retarded monkey" on his avatar?
That's a bit harsh don't you think?
 
2:56 AM
@RMartinhoFernandes he'll be fine :D
what? the monkey does look dumb
and angry as well =D
and his profile states clearly, "I'm The Grumpy Old Ape." :P
 
You'll make him even angrier by referring to said ape as a "monkey".
 
Crap, I'm 9 upvotes away from a Java badge!
 
goes through Kerrek's profile, serially upvoting his Java answers
 
Can you prevent a badge by collecting downvotes? I could go and post some very stupid Java answers.
Like, "no, no, that's far too simple; you must use an abstract factory to create a wrapper". I could just post this blindly for every Java question that comes up.
@RMartinhoFernandes Don't you dare!
I still want to be employable...
 
@KerrekSB Are you sure that would garner you downvotes?
Ha! You have a PHP badge!
 
3:05 AM
Hi there.
 
@RMartinhoFernandes - Question about ifstream.
 
Also, can I please get some "too localized" close votes here?
 
@RMartinhoFernandes Where?
@RMartinhoFernandes Moshe For Mod!
 
I think we need to lay a strong hammer on RTFM questions.
Oh, silly me. Should post a link.
0
Q: Please tell me the meaning of format {0:d}

Lu LuI don't understand the meaning (purpose) of using specifier d for string format. Example: Input: double 1.2345 -> Output: System.FormatException Input: int -12345 -> Output: -12345 Refer: http://idunno.org/archive/2004/07/14/122.aspx#a2004071402-culture Please help me. Thanks.

 
3:06 AM
About ifstream...
If I use it like this:
 
@RMartinhoFernandes I'm moderately entertained by the PHP badge. I think I got it without unravelling deeply nested arrays, too...
 
ifstream fin("names.txt");
Then my program will work
 
Wouldn't mind a golden C++11 badge, but that tag is a mess
 
@KerrekSB Why so? (I'm on bronze :P)
 
@RMartinhoFernandes What's too localized? Ahh, the {0:cd} guy?
 
3:07 AM
When I do something like fin.open("names.txt") it fails when run outside of my IDE?
 
@Moshe Check paths. Does it work if "names.txt" is the full path?
@KerrekSB Yes. I forgot the damn link.
 
@RMartinhoFernandes It's in the same directory.
 
@RMartinhoFernandes I think too much of it is splintered into the old C++0x tag, which soaked up lots of good posts... now it's back to square 1
 
@KerrekSB Me in an initial bootstrapping effort, and Johannes in a move of jealousy to become the top user moved a lot of them.
@Moshe Ok then, what form does this failing take? Exceptions? Something else?
 
@RMartinhoFernandes if(fin.fail) becomes true
 
3:11 AM
Oh right, streams don't throw by default.
 
@RMartinhoFernandes Meh, I got 57 C++0x and 45 C++11 votes :-(
 
Does it fail right after the open, or after some reading?
 
So am I doing something wrong? When I use the one liner it runs when invoked by the user and when run from the IDE.
@RMartinhoFernandes Right after.
 
@Moshe fail is set if you perform an invalid extraction, too.
 
That's weird.
 
3:13 AM
@KerrekSB !fin.is_open() yields the same
Ok, the Town Hall killed my night. I have work to do.
 
@Moshe Well, as RM says, most likely the file just isn't there...
 
It is, probably path issues.
 
3:26 AM
yesterday, while just exploring some issues, i wrote what i now think is moron code (it is intentionally compiler-specific, using a non-std constructor)
can you spot the eror:
void init( wostream& stream, FILE* f )
{
    locale const    utf8Locale( stream.getloc(), new codecvt_utf8_utf16<wchar_t>() );
    FILE*           utf8OutFile = withModeFix( f, "failed to set utf8 mode" );
    wofstream       wOutStream( utf8OutFile );

    wOutStream.imbue( utf8Locale );
    stream.flush();
    stream.swap( wOutStream );
}
possibly i was very tired, but what i was thinking was that if it compiles and apparently works, then must be correct...
 
No, I don't see it :(
Does locale take ownership of the codecvt?
 
yes
well i'm talking about the swap
the stream is a wostream, and I try to swap it with a wofstream.
 
which is a derived class
 
Why does it even compile?
 
3:32 AM
oh, compile. wofstream is derived from wostream
 
Oh, right of course. The swap in wostream matches.
 
i think
ok the flush should be first also, don't know how it moved to second position
 
How do you construct the fstream from a FILE*, though?
 
@KerrekSB I guess that's the compiler-specific part he mentioned.
 
@RMartinhoFernandes I should hope so!
 
3:35 AM
@KerrekSB that's the compiler-specific thing. the more proper code instead constructs a filebuf from a FILE*. because both msvc and g++ support that (in slightly different ways)
 
@AlfPSteinbach How to do that in GCC?
I like my little make_file manager...
 
@KerrekSB see the documentation
 
I have this enum, with three values a, b, and c and I want another value that is guaranteed different from all three. I could just define all values manually, but since this is actually a wrapper for a C API with macros, that would need a function to translate the values. I'd rather have a, b, and c equal the underlying macros. Ideas?
 
@AlfPSteinbach Jesus Christ, not tonight :-)
@RMartinhoFernandes a+b+c?
 
@KerrekSB What if a = UINT_MAX, b = 0, and c = 1?
Yes, it's possible one of them is zero :(
 
3:39 AM
OK, 11*a + 17*b + 31*c then.
 
(I'm being way too paranoid, because I'm sure they will probably always be 0, 1, 2, but I thought it was a good exercise.)
 
You should do like a hash table. Make an ordinary map<YourEnum, bool>, insert a, b and c as false, and then compute the new f(a,b,c).
If it doesn't exist, bingo; otherwise, you do chaining and set the bool to true.
 
Use some silly conditional operators?
 
@KerrekSB But a hash table does not guarantee no collisions, only low rate of collisions. But I believe your example with all primes multiplying works.
 
@KerrekSB sry the link was wrong should be here
 
3:44 AM
@RMartinhoFernandes No rule can work for all values. You can always solve f(a,b,c) - a = 0.
So you have to cater for collisions.
But with template magic, I'm sure we can rig up a compile-time open-addressing hash table in TMP in no time.
(Luc Danton probably already has one of those in production.)
 
@AlfPSteinbach Ohhh. That's much better!
 
@KerrekSB Oh, right. How could I not see that.
Since these are only three values, I think a bunch of conditionals will have to do. Also, this code is not exactly for experienced C++ers, so I'd rather not go overboard with templates.
 
OK, in seriousness, you should be able to make a template unique_new_value<int...>::value that gives you a new value that's not on the list.
max<int...>::value + 1 comes to mind
 
@KerrekSB Overflows!
 
3:50 AM
Add a condition for that.
 
Wait, I think enum foo { a = WRAPPED_A, b = WRAPPED_B, c = WRAPPED_C, d = a+b+c }; actually works!
 
Or a+1 if not taken, otherwise b+1 if not taken, otherwise c+1 if not overflow, otherwise min(a,b,c) - 1. Something like that.
 
If I don't specify the underlying type, it won't overflow, right?
(And I'm guaranteed a, b, and c are distinct, thus no two of them are zero)
Damn, wait, the values are int.
a = -1, b = 0, c = 1 would fail.
Damn, I really have no idea how enum values are assigned.
 
You can sort and check for existence at compile time.
So you should be able to find a hole in a collection at compile time, too
 
@KerrekSB I can't say I have :)
 
3:57 AM
@LucDanton I'm sure you've thought about it!
 
Hmm, enum foo : unsigned long long { a = WRAPPED_A, b = WRAPPED_B, c = WRAPPED_C, d = a+b+c }; should work, no? (I'm assuming unsigned long long is strictly larger than unsigned. Screw silly platforms.)
 
I can't say I have.
@RMartinhoFernandes You can wrap around to a value already taken, can't you?
 
@LucDanton I'm guaranteed the WRAPPED_* values fit in an int.
 
Hmmm. I think a simple modular argument shows that if S is a subset of Z_n and S+1 is the same as S, then the size of S must be n.
 
What does +1 do when applied to a set?
 
4:01 AM
Just +1 to each element
S + 1 := {x+1 : x \in S }
 
Ah, ok.
I don't see how that applies here though.
 
For contradiction, assume that all successors of your set are already taken. Then n = 3.
But n = 2^32, so you're safe
 
Since I'm assuming unsigned long long can hold 2^8 (bytes are not allowed less than 8 bits) times more values than unsigned, I think that's not an issue.
 
So you know that at least one of the successors cannot already have been a member of the original collection
And you can find that one efficiently (at compile time, anyway).
 
A != 0 && B != 0 && C != 0? 0 : A != 1 && B != 1 && C != 1? 1 : A != 2 && B != 2 && C != 2? 2 : 3 Brute force!
 
4:09 AM
move! no, don't move! "void swap(basic_ios& rhs); Effects: The states of *this and rhs shall be exchanged, except that rdbuf() shall return the same value as it returned before the function call, and rhs.rdbuf() shall return the same value as it returned before the function call."
 
How can I get this to compile?
constexpr bool is_unique(int n) {
return true;
}

template <int a, int... av>
constexpr bool is_unique(int n) {
return (a != n && is_unique<av...>(n));
}

template <int... av>
constexpr int unique(int acc = 0) {
return is_unique<av...>(acc) ? acc : unique<av...>(acc + 1);
}
 
@RMartinhoFernandes Indeed. Any set of size 4 must contain one unoccupied member.
 
@Pubby Use a <int, int...> and a <int> overloads. No promises it works though.
Possibly make the first one a <int, int, int...> overload, even.
 
@Pubby But it compiles: ideone.com/zuJBq
:)
 
Not sure you can -- overloads have to have distinct signatures if I'm not mistaken
 
4:12 AM
I'd pass the stuff as params.
 
It doesn't compile when I try to use it: std::cout << unique<5, 6, 2, 3>();
 
What is it supposed to do anyway?
 
Solve my problem for arbitrarily-sized sets?
 
Yeah, was trying to
 
I would never use function calls for compile-time magic; always go for template parameters and static member constants.
 
4:13 AM
Not even constexpr?
 
constexpr functions are not guaranteed to be evaluated at compile-time.
 
RM's idea should have a straight-forward template implementation, though. Do a "static-for" over the first 1 + sizeof...(args) numbers and check which of them does not occur in the collection.
@Pubby No, why... the horrors. Integral constants do just fine.
 
There's an implementation-defined recursion limit, and if it is hit, the compiler switches to runtime evaluation. I seem to remember it that way.
If you do such a "constexpr but runtime anyway" call in a context that requires a constant expression, it errors out.
@KerrekSB It's a fold!
Lemme grab my code from the other day :)
Oh wait, that code was runtime.
 
@RMartinhoFernandes Hehe, isn't it always :-)
 
I'd write a generic fold for templates, but that's probably on Boost.MPL already.
Boost.MPL scares me though.
 
4:38 AM
@RMartinhoFernandes You're not the only one. Most C++ programmers have not even heard of it.
 
How can you be scared of something that you don't know exists?
 
Now I'm really confused. is_unique<n> is being called even though it's not possible.
return sizeof...(av) ? (a != n && is_unique<n, av...>()) : a != n;
 
@RMartinhoFernandes they forget about it because when they first see it they get very scared
^ my theory
 
void init( wostream& stream, FILE* f )
{
    wofstream       mystream( f );
    locale const    utf8Locale( stream.getloc(), new codecvt_utf8_utf16<wchar_t>() );

    assert( !stream.fail() );
    stream.flush(); fflush( f );

    mystream.imbue( utf8Locale );
    auto const oldBuf = mystream.rdbuf();
    stream.swap( mystream );        // Without swapping, subsequent output crashes.
    auto const newBuf = mystream.rdbuf();
    assert( oldBuf == newBuf );     // The partial swap behavior of std::basic_ios::swap.
^ If I could only find out why output causes crash when I don't swap. g++ doesn't support the swap, it needs file buffer level fixups. MSVC needs the swap and does not agree with the file buffer level fixup.
 
4:57 AM
I think having override trailing is not as good as leading. If it's leading, editors can benefit from it.
 
I hate to ask another question, but is sizeof... allowed in template arguments for specializations?
 
There's no problem in asking. I don't know the answer though.
 
5:22 AM
@Tenev You misspelled "standard" ;)
 
Secure';. The title is cool.
 
I'm all pleased with myself over this question: stackoverflow.com/questions/8147027/…
 
@Omnifarious What's so pleasing about it?
 
Well, it's simple and direct, and it's clear that it's a reasonable problem to want to solve.
But there is no easy answer.
 
Yeah, I don't think you're getting the answer you want :(
 
5:35 AM
I think a lot of people using the protected constructor/public create method to create shared_ptr's are going to want an answer to this question.
 
@Omnifarious would you like me to answer that after i made new cup of tea?
 
I just wrote an answer.
 
@LucDanton ok
 
@AlfPSteinbach Does it cover what you wanted to write yourself?
 
Mine is much ickier, but allows things to still be inline.
 
5:44 AM
@LucDanton yes. i would probably have forgot to mention that it doesn't require polymorphic class. but otherwise. :-)
 
@LucDanton Mine basically involves making a private class inside A that the constructor requires a reference to, then making the constructor public.
 
You could make that an answer or edit it into your question. It's not an unreasonable solution.
 
class evil_A : public A {}; A* a = new evil_A();
What about this?
 
@RMartinhoFernandes Well, yes, anybody could do that. But if they do, they deserve what they get for purposely circumventing your restriction. The goal is to prevent accidental mistakes, not purposeful mistakes.
 
5:55 AM
@LucDanton I added it as an answer.
 
That's a good point.
 
@Omnifarious "Protect against Murphy, not Machiavelli".
 
Java seems to take the opposite approach.
 
Where's mah oneboxing!
 
@LucDanton Ahh, interesting. I didn't realize it did that.
 
6:02 AM
@LucDanton Only on message-specific replies.
4
Q: Is a virtual destructor needed for your Interface, if you always store it in a shared_ptr?

XeoSince boost::/std::shared_ptr have the advantage of type-erasing their deleter, you can do nice things like #include <memory> typedef std::shared_ptr<void> gc_ptr; int main(){ gc_ptr p1 = new int(42); gc_ptr p2 = new float(3.14159); gc_ptr p3 = new char('o'); } And this wil...

Like this.
 
I would have thought the system would consider "@Soandso" specially, just like it treats ":1234567" specially.
 
Yeah right, as if chat was that consistent.
 
6:24 AM
I finally got that example program down to reasonable minimum size. I had forgotten that I added all that stuff with code conversion facets and locale and file buffers just because g++ needed it. The Visual C++ "solution" does not even pretend to have anything to do with standard library ways:
code paste <- it's interesting in a way, how to deal with Unicode console output in Visual C++ in Windows
then for other compilers, like g++, other ways...
 
6:52 AM
morning
 
OMG, it really is morning.
 
@RMartinhoFernandes TIL
 
here's a question
 
good morning
 
does it really work to allow postfixes with ++ and --?
 
6:55 AM
it is morning, and it's waaayyyyy too early
 
like identifier++(0);
 
I guess that logically, you could have overloaded that op to do anything, e.g. expression templates
 
But I don't like the idea.
 
so it would be bad of me to prevent it
 
6:57 AM
0
Q: Why does `basic_ios::swap` only do a partial swap?

Alf P. Steinbach C++11 §27.5.4.2/21: void swap(basic_ios& rhs); Effects: The states of *this and rhs shall be exchanged, except that rdbuf() shall return the same value as it returned before the function call, and rhs.rdbuf() shall return the same value as it returned before the function call. ...

 
well the thing is, people could always just do (identifier++)(0) anyway to make it parse
 
Yeah, the source of the "issue" is the fact that x++ is an expression.
But making it a statement is too restrictive I think.
 
well
I was thinking of introducing a "C" class that would parse C source files and make them available as WideC :P
so arguably, I'd want to do C++("filename") if I wanted to do the same for C++
 
Err.
Do you have a postfix # operator?
 
lol
 
7:04 AM
;)
 
no
here's a question
in C++, why the hell is it UB to shift more than the amount of bits?
I understand that different platforms have different treatments of this condition
but as far as I know, they all just return some different funky value
so why not just make the return unspecified?
 
@DeadMG there could conceivably be a processor that trapped automatically on too large shifts
 
if it doesn't actually exist within common usage, I'm not bothered
 
But, but, the children!
 
fuck em
 
7:11 AM
What?
 
fuck the children
 
You know, if I flagged that, I'm pretty sure it would be validated enough times to suspend you :)
(Not that I think it should or anything, just stating a fact.)
 
lol
meh
ARGH INTELLISENSE Y U SO SLOW :(
 
IntelliSense is for pussies.
 
@RMartinhoFernandes You know, if I flagged that, I'm pretty sure it would be validated enough times to suspend you :)
 
sbi
7:20 AM
I inexplicably lost 54 rep over night. Did we have a recalc?
 
Not that I know of.
@AlfPSteinbach What's wrong with cats?
Cats can't type correctly, so they need IntelliSense.
 
I gained 0 rep for an old answer. Dunno why it should show me that.
@RMartinhoFernandes cats walk over keyboards and through walls. the latter shows that they lack intelligence and sense.
 
sbi
@RMartinhoFernandes So someone must have deleted a question I had lots of rep invested. But then, wouldn't that also only deducted after a recalc?
 
@AlfPSteinbach Past the rep cap?
@sbi Hmm. No idea. Does it show on the rep tab on your profile? What about the audit page?
 
7:26 AM
Though I wouldn't notice if we had a rep-recalc. I regularly trigger manual recalcs, so my rep would likely be unaffected by a global recalc.
 
7:47 AM
@RMartinhoFernandes I finally got that unique template to work.
 
Do show it.
 
I was wrong about Lua, it isn't as useless as I thought.
It's quite good actually, I just embedded it into my app in less than 5 minutes.
and the cleanest C Api I ever saw...
 
@RMartinhoFernandes pastebin.com/HYn1sNw4
A bunch of conditionals seems like a better idea >_<
 
@Pubby In the end, I didn't even use conditionals. I changed the design slightly so I don't need that hackish enumerator :)
 
Hah, I guess that's the best way to solve it
 
7:53 AM
You compiled that with clang?
Arrgh. I want initializer lists in clang, or template aliases in GCC.
 
No, GCC
 
Oh, how recent is your snapshot?
I want me some template aliases :)
 
I think it's only a few days old
20111112
 
Hmm, I found a 20111108 MinGW build. Let's hope it's there :)
 
Nope, it has to be past 20111112
 
7:56 AM
Oh :(
 
Well, maybe not. Last I tried was 20111015
 
@IntermediateHacker industriousone.com/basic-script (just a tab i had left open in the browser)
 
Hmm, besides concurrency, C++11 support is very close to complete: gcc.gnu.org/gcc-4.7/cxx0x_status.html
> User-defined literals N2765 Yes
Yay!
 

« first day (396 days earlier)      last day (4545 days later) »