WINAPI thread problem

This is a discussion on WINAPI thread problem within the Windows Programming forums, part of the Platform Specific Boards category; Hey there, I've been working on this project for a long time now and can't seem to find how this ...

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21