CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Oct 2008
    Posts
    45

    threading problem

    Code:
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <process.h>
    using namespace std;
    
    unsigned int __stdcall foo(void *param)
    {
    	while(1) cerr<<"howdeee\n";
    	return 0;
    }
    unsigned int __stdcall foo2(void *param)
    {
    	while(1) cerr<<"NOOOOOOOOO\n";
    	return 0;
    }
    void main()
    {
    	_beginthreadex(NULL,0,foo,NULL,0,0);
    	_beginthreadex(NULL,0,foo2,NULL,0,0);
    	while(1) cerr<<"FORk\n";
    }
    I have core quad computer so threads can run in parallel on different cores, but what I'm getting as an output is:
    howdeee
    FORk
    NOOOOOOOOO

    in this pattern repeating for ever, thats not what I expexted I expected them to be randomly printed mabe two howdeee then a FORk then NOOOOOOOO then maybe a FORk ect... since threads run in parallel :S. but as is it seems they are running serially foo then main then foo2 any ideas of why this is happening?

    thanks in advance
    Last edited by compuKidd; December 14th, 2008 at 09:54 AM. Reason: spelling mistake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured