Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fibers and mutexes #937

Open
dibyendumajumdar opened this issue Dec 2, 2024 · 6 comments
Open

Fibers and mutexes #937

dibyendumajumdar opened this issue Dec 2, 2024 · 6 comments

Comments

@dibyendumajumdar
Copy link

Hi, first of all many thanks for creating such a marvelous product.

I am trying to use Tracy in a system that has fibers and fiber mutexes.
I notice that fibers show up in the capture - but not mutexes.
If I disable fibers and use threads, then mutexes show up.

Is there an assumption that mutexes are thread based?

@wolfpld
Copy link
Owner

wolfpld commented Dec 2, 2024

Support for mutexes with fibers is probably not implemented now.

@dibyendumajumdar
Copy link
Author

dibyendumajumdar commented Dec 2, 2024

Is this a problem in the front-end (i.e. server)?

@Sven-v-Beuningen
Copy link

Yes, it's running for several loops, bun then stops with the "zone ended twice" message:

image

@dibyendumajumdar
Copy link
Author

dibyendumajumdar commented Dec 3, 2024

I got similar issue initially but that seems to be caused by incorrect or missing Fiber Enter instrumentation.

p.s. although in your case it may be mismatched Zone start/end?

@dibyendumajumdar
Copy link
Author

dibyendumajumdar commented Dec 3, 2024

In our code we have fiber mutexes, that work just like thread mutexes.
So I can switch the code between fiber version and thread version.
The instrumentation for mutex is unchanged and works fine in the thread version - so the issue might be that the Tracy frontend (server) is not associating a mutex lock with the active fiber.

@Sven-v-Beuningen
Copy link

Thank you very much, for the reply. I'm pretty sure, I do something with entering and leaving the coroutines wrong, but I don't know how to do it right. The best results I do get with the following code in my thread function:

auto JobSystemWorker::workerFunction() -> void
{
    m_running = true;
    while (m_running)
    {
        auto job = std::move(getJob());

        if (job)
        {
            TracyFiberEnter(m_workerName);     
            (*job)();
            TracyFiberLeave;
        }
    }
}

With "best results" I just mean, that the zones look correct in the server. But it still stops after some loops.
In the thread function I just try to grab a suspended coroutine and resume it. It can happen, that the same coroutine is suspended and resumed multiple times, because the coroutine can have multiple lines with "co_await". It can also happen, that a coroutine is resumed by a different thread, than the one which has suspended it.
If I run my application just with one thread, everything works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants