Shared posts

19 Apr 04:59

Jim Carrey and Metal music (Press unmute)

by admin
26 May 17:41

Living the Life

Untitled

Submitted by: Unknown

31 Jan 20:02

CodeSOD: Overloaded Loop

by Remy Porter

Brian found himself digging through some C++ code, trying to figure out a cross-thread synchronization bug. It had something to do with the NetLockWait function, based on his debugging, so he dug into the code.

bool CMyDatastore::NetLockWait(DWORD dwEvent, long nRecord, CMySignal& Signal, DWORD dwTieout)
{
    bool  retBool;
    long  value;
    DWORD reason;
    DWORD currentAttach;
    CTimerElapsed timeout;

    timeout.SetTime(dwTimeout);

    retBool = false;

    while (timeout)
    {
        if (::WaitForSingleObject(Signal.GetEvent(), timeout) != WAIT_OBJECT_0)
        {
            break;
        }

        ReserveSynch();
        Signal.Pop(reason, value);
        ReleaseSynch();

        if (reason == dwEvent && value == nRecord)
        {
            retBool = true;
            break;
        }
    }
    return (retBool);
}

While reading this, something leapt out to Brian- the variable timeout was never changed inside the loop. So, this is a simple bug, right? The timeout is basically ignored, and the loop keeps retrying until it hits one of the break statements?

Well… no. In fact, the loop did successfully time out, and timeouts had nothing to do with the synchronization bug. Brian couldn’t help but be curious- how did the timeout actually get decremented?

CTimerElapsed::operator DWORD(void)
{
    DWORD wait = 0;
    DWORD dwCurrentTick;
    DWORD dwElapsed;

    if (m_dwTimeout == INFINITE)
    {
        wait = INFINITE;
    }
    else
    {
        dwCurrentTick = ::GetTickCount();
        if (dwCurrentTick < m_dwStartTicks)
            dwElapsed = (UINT_MAX - m_dwStartTicks) + dwCurrentTick;
        else
            dwElapsed = dwCurrentTick - m_dwStartTicks;

        if (dwElapsed < m_dwTimeout)
            wait = m_dwTimeout - dwElapsed;
    }

    return (wait);
}

A number of languages prohibit operator overloading, for good reasons. C++ is highly optimized for autopodóplo- shooting ones own foot. Thus, C++ cheerfully lets you create this monstrosity.

This block here overrides the DWORD type cast- whenever a CTimerElapsed object is used where a DWORD is expected, this code is called to convert the CTimerElapsed instance into a DWORD, decrementing the count, and pushing the boundaries of what operator overloading is for.

This code was not the source of Brian’s bug. This code works. It’s not wrong, but it’s wrong.

[Advertisement] Onsite, remote, bare-metal or cloud – create, configure and orchestrate 1,000s of servers, all from the same dashboard while continually monitoring for drift and allowing for instantaneous remediation. Download Otter today!
12 Nov 17:49

Full-camo Ferrari F12 M spied testing in Maranello

by Michael Austin
11 Oct 18:03

20 Must watch TED talks

by admin
funny pictures
08 Jun 20:01

It's Important Not to Skip Any of the Steps

07 Jun 07:06

It's a New Day Exactly Like the Old One

18 Jul 19:48

Daily Morning Epicness (40 Pictures)

by admin


1


2


3


4


5


6


7


8


9


I see what you did there.

10


11


12


13


14


They never grow up

15


16


17


18


19


Some assholes in Stockton robbed a bank and took a 12 yr old hostage. This was their car after the car chase.

20


21


22


23


Why you shouldn’t fall asleep at the beach

24


25


26


27


One of the creepiest thing I found when looking through old photos

28


29


30


31


290 to 180 and done. Myfitnesspal.

32


33


34


35


I knew having trashy Facebook friends would eventually pay off.

36


37


38


39


The struggle is real

40
11 Jul 14:32

Every Movie Is Better with Batman

by John Farrier

Driving Miss Daisy

There are good movies. There are even great movies. But every moive--and I do mean every movie--can be improved simply by adding Batman as a character. The blog It's Better with Batman is dedicated to proving that by photoshopping the Dark Knight into famous scenes.


American Beauty


Full Metal Jacket


E.T. the Extra-Terrestrial


The Lion King


Jaws

See? Just like I said: every movie.

But all of us at Neatorama promote an open exchange of ideas, even heretical ones. So if you wish to argue that a movie could not be improved by adding Batman, please state your case in the comments.

-via Nerd Approved

08 Oct 12:13

Astrophysicist Neil deGrasse Tyson Fact-Checks Gravity on Twitter

by Angela Watercutter
Director Alfonso Cuar?n's film Gravity just had an amazing weekend, raking in a record-breaking $55.6 million at the box office. There was just one little snag: Beloved astrophysicist Neil deGrasse Tyson showed up on social media to poke some scientific holes in the story about astronauts stranded in space.
    






16 Aug 21:34

How a hockey star destroyed a nasty online troll on Twitter

by Jesus Diaz on KINJA, shared by Kyle Wagner to Gizmodo

How a hockey star destroyed a nasty online troll on Twitter

Ice hockey star Paul Bissonnette (right) can smash your nose with a punch both in the rink and in the internet. The Coyotes player was being harassed by a typical Twitter imbecile called Matt Hogue (left) when he decided to play hardball on the troll. The results were delicious.

Read more...