Find threads belongs to object ?

Posted on 2006-05-17
Last Modified: 2010-04-01
Hello experts !

How can I find what thread belongs to object ?
I have DirectShow FilterGraph (IFilterGraph) that contains some filters. FilterGraph have some threads and I want to find all of them. How to do it ?
Question by:dvplayltd
    LVL 8

    Expert Comment

    I have not checked it but:

    You can call GetCurrentProcessId() to get ID of you process,
    call GetCurrentThreadId() to get ID of current thread and

    use "Tool Help Functions" to enumerate all threads and find all threads that has your process ID as parent process id

    Call CreateToolhelp32Snapshot()

    and then

    Thread32First(), Thread32Next()

    Author Comment

    I use FilterGraph that hold DirectShow filters. SOme DirectShow fileters may have thread and I think that they are child for FilterGraph. Using parent/child will help me get DirectShow filters thread.

    But how to find thread of FilterGraph ?
    Is using GetCurrentThreadId on code where is created  FilterGraph will tell me ThreadId of FilterGraph ?
    LVL 8

    Accepted Solution

    As far as I know FilterGraph uses so called application thread  - thread on which object has been created (so I think GetCurrentThreadId() should be what you need) & there can be one or more working threads created later.

    If you want however find working threads ... that's a problem. If you have control over thread creation you can simple store somewhere their IDs.

    Additional working threads will be created after graph is run so you could enumerate threads before start & enumerate after & find new threads (just idea).

    I don't want to lie but I think there's no such relation like parent thread-child thread.


    Author Comment

    Thank you mrblue but I can NOT use enumerate before and enumerate after, because meantime my Process may create another threads. it look like I have to forgot about  easy way and maybe skip idea.

    I will wait one- two days to see other answers and if do NOT - I will accept your aswer.
    LVL 86

    Assisted Solution

    Unless you hook the thread creation, you'll hardly be able to associate a certain thread with an associated DirectX object later on. There also might be some threads that aren't even related to DirectX.

    Author Comment

    thank you jkr, your answer is correct but mrblue was first :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now