Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Threading, without threading?

Name: Anonymous 2012-08-07 15:58

Allow me to explain:

int x;
int y;

void inc_x() { x++; }
void inc_y() { y++; }

int  get_x() { return x; }

int main() {
    int i;

    for( i = 0; i < 10; i++ ) {
        inc_x();
        inc_y(); // executed after inc_x(), but why wait?
                 // why not execute inc_y() in a separate thread?
                 // So, is this 'automatic threading' been done before?
                 // Is it even possible?
    }

    return get_x();
}

Name: Anonymous 2012-08-07 17:59

Your compiler optimized the code in a way that made it so the calls are done in reverse order (I'm surprised the calls are made at all, you must not be optimizing it to the fullest), this kind of optimization is possible because the two symbols, x and y are not dependant of each other in that part of the code and are not marked volatile.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List