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

Threading not working as expected on Linux #8

Closed
d-Pixie opened this issue Feb 17, 2012 · 8 comments
Closed

Threading not working as expected on Linux #8

d-Pixie opened this issue Feb 17, 2012 · 8 comments

Comments

@d-Pixie
Copy link
Contributor

d-Pixie commented Feb 17, 2012

Problem

When building on Linux the variable for threading gets set to 1 all through the CMake config, CMake headers and generated headers. No warnings or errors during compile but the audioManager does not get updated automatically as expected on a threaded version of the library.

Symptoms

All the examples, where the threaded library should make music play through to the end, requires an additional line of audioMgr->update() in the while(mysound->isPlaying()) block to work as expected.

Investigation

I followed the code to the point that I'm sure it's configured correctly and that pthreads gets included in the build. However I think the assistance of a main developer on this issue might get us to a resolution faster.

Solution

I'm prepared to spend time and effort on fixing this issue, seams logical since I'm building on Linux anyways, but would request the help of a developer to get into the code faster (no point in floundering around for a week ;o). Contact me if you can help. I'll get stuck in in the meanwhile...

@ghost
Copy link

ghost commented Feb 18, 2012

I am not currently working on a linux machine however i will look into the issue you are having.

@d-Pixie
Copy link
Contributor Author

d-Pixie commented Feb 18, 2012

I had another, closer, look at the code today and I can see that in src/cThread.cpp lines 23 - 41:

bool cAudioThread::start() {
    cAudioMutexBasicLock lock(Mutex);

    if(IsInit) 
        return IsInit;

        IsInit = true;

    #ifdef CAUDIO_PLATFORM_WIN
    ThreadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, threadFunc, this, 0, &ThreadID));
    if(ThreadHandle == 0)
        CloseHandle( ThreadHandle );
    #else
    ThreadID = pthread_create( &ThreadHandle, 0, threadFunc, this ); 
    #endif
        IsInit = ThreadID != 0;
    return IsInit;
}

the function returns false on linux, the thread never gets created.

I'll look some more at the docs for this tomorrow and see if I can figure out why this would be. I have already made sure that cmake configures gcc to run with the -pthread option (as indicated it should by googling a bit ...) but that had no effect.

If you have any idea of what might be wrong here please dont hessitate to point me in the right drection ;o) I have never played with threads before, so this might be a long ride for me othervice ...

@ghost
Copy link

ghost commented Feb 18, 2012

Installing a linux box so i can begin testing.

@d-Pixie
Copy link
Contributor Author

d-Pixie commented Feb 19, 2012

Found the problem. This section:

    #else
    ThreadID = pthread_create( &ThreadHandle, 0, threadFunc, this ); 
    #endif
        IsInit = ThreadID != 0;
    return IsInit;

should be:

    #else
    pthread_create( &ThreadHandle, 0, threadFunc, this ); 
    #endif
        IsInit = ThreadHandle != 0;
    return IsInit;

With that fix threadin works as expected on Linux as well ... I'll open a pull request for the fix in a sec ;o)

@ghost
Copy link

ghost commented Feb 19, 2012

Awesome i got caught up yesterday and i wasn't able to look into it. glad you found it. Ill pull once you submit

@d-Pixie
Copy link
Contributor Author

d-Pixie commented Feb 19, 2012

Pull request issued ;o) I'll close this issue now.

@d-Pixie d-Pixie closed this as completed Feb 19, 2012
@ghost
Copy link

ghost commented Feb 19, 2012

Just tested on windows its working correctly. GJ

@d-Pixie
Copy link
Contributor Author

d-Pixie commented Feb 19, 2012

Thank you ;o)

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

1 participant