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

Pages: 1-

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 16:17

Not really. You would have to be 100% inc_y() doesn't depend on any state which will be mutated by inc_x(), which is impossible.

Name: sdafasdf 2012-08-07 16:34

Name: Anonymous 2012-08-07 16:52

Anything is be possible here, you're incrementing two uninitialized variables.

Name: Anonymous 2012-08-07 17:43

javascript does this

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.

Name: Anonymous 2012-08-07 18:08

>>6
Optimizing it to the fullest would be not producing any output. The compiler can do anything once it finds undefined behavior, including just not doing anything.

Name: Anonymous 2012-08-07 18:15

>>1
The implementation has to behave ``as if'' they happened in order they would on the abstract machine. If there's no way for the program to ``observe'' a discrepancy without resorting to undefined behavior, they can take place simultaneously.
>>4
Global/static variables in C are initialized to zero. Nice tryoll though.

Name: Anonymous 2012-08-07 18:50

Goroutines, Cilk.

Name: Anonymous 2012-08-07 19:37

Kind of similar to your example is asynchronous I/O.

>>2
Haskell gets around this by forcing you to mark any state as such with a monad, which lets it process things in whatever order it wants. It doesn't matter because there's no state.

>>8
tryoll

Name: Anonymous 2012-08-07 21:13

>>8
Global/static variables in C are initialized to zero
ebin troll bro :DD

Name: Anonymous 2012-08-07 22:33

>>11
K&R are such trolls! xD
And your dubs are cool bro!

Name: Anonymous 2012-08-07 23:21

>>1
OP use Coq and suck COCK!

Name: Anonymous 2012-08-07 23:22

>>13
no really use Coq, it's a total language (it can evaluate in whatever order and produce the same result) so the reorganization is possible.

Name: Anonymous 2012-08-08 10:10

>>2
Hello there, 1992.  In 2012 even single-core CPUs are able to execute a lot of instructions in parallel.

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