passing data from thread to main process

This is a discussion on passing data from thread to main process within the C++ Programming forums, part of the General Programming Boards category; I have just read chapter about threads and I just want to ask quick question. What is the best way ...

  1. #1
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92

    passing data from thread to main process

    I have just read chapter about threads and I just want to ask quick question. What is the best way to pass data from threads to main process? Is it using global variables ( and of course using mutex ) or using pthread_setspesific and pthread_getspesific function?

    You know, this chapter make me confuse so much. Thank you.
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    You can use a pipe to do this. When creating the thread, it can inherit a handle to the pipe, which can be used to write data to the pipe. The main process can read from the pipe when necessary. There may be better ways to do this though.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    You are referring to a UNIX platform, correct?

    One solution is a global variable as you have already mentioned. Another solution is a callback function. Another solution is pointer.

    Kuphryn

  4. #4
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92
    Callback function? I m sorry. I never heard about this one. I know about mutex, conditional variables but not this. Yes, I refer to posix implementation.
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get process info ( to extract process thread id )
    By umen242 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2009, 01:08 PM
  2. Passing data between a thread and a form
    By DanFraser in forum C# Programming
    Replies: 14
    Last Post: 11-28-2008, 02:52 AM
  3. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 01:16 PM
  4. Replies: 4
    Last Post: 06-14-2005, 06:45 AM
  5. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 02:37 PM

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