Thread: WINAPI thread problem

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    WINAPI thread problem

    Hey there,
    I've been working on this project for a long time now and can't seem to find how this is done.

    c++ language under windows.

    I created 4 threads. Inside one of the threads I want to call another thread funtion. How is this done?? Cause it does not seem to work like other threads.

    Thanks so much in advance.

    Code:
    DWORD WINAPI R1 (LPVOID)
    {
          while(TestAndSet(&lock))
              while(lock==true);
    
    	readcount++;
    	cout << "R1 in CS." << endl;
    	cout << readcount << "Readers in CS." << endl;
    	cout << writecount << "Wrtiers in CS." << endl;	
    	
               //want to call a thread here. example R#2.
    		
                   readcount--;
    	  lock=false;
    			
    		return (DWORD) 0;	
    	
    			}

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Functions don't belong to a thread of course, you can generally call a function from whatever thread, it's just that it will execute in the thread that calls it.
    Are you actually wanting to have one thread cause a different thread to call a particular function? Then are you perhaps wanting to wait until that other thread has finished that call?
    Or perhaps you're wanting to call a member function but the thread proc is a static method so it obviously wont let you?
    Can you show us what you've tried and what compiler errors you get?

    The code you've posted already looks rather dubious. That spin-lock locking mechanism just doesn't sit well with me.

    Could you fix the indentation as well please?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Problem with WinApi
    By danepporambo in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2006, 12:26 AM
  3. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 11:34 PM
  4. Sign-up Thread: Problem Solving #1
    By ygfperson in forum Contests Board
    Replies: 15
    Last Post: 01-26-2003, 02:55 AM
  5. Multi-Thread Programming
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2002, 02:53 PM