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

ppu-g++ std::thread problem #122

Open
humbertodias opened this issue Mar 8, 2024 · 2 comments
Open

ppu-g++ std::thread problem #122

humbertodias opened this issue Mar 8, 2024 · 2 comments

Comments

@humbertodias
Copy link

humbertodias commented Mar 8, 2024

Is there anything missing on ppu-g++ to compile std::thread ?

Trying to compile std::thread

docker run -i --rm zeldin/ps3dev-docker bash -s <<EOF
echo '#include <iostream>
#include <thread>

// Function to be executed by the thread
void threadFunction(int threadID) {
    std::cout << "Thread " << threadID << " is executing" << std::endl;
}

int main() {
    // Creating a thread and passing a function to execute
    std::thread t1(threadFunction, 1);

    // Joining the thread to the main thread
    t1.join();

    // Output a message from the main thread
    std::cout << "Main thread is executing" << std::endl;

    return 0;
}' > oo.cpp
ppu-g++ oo.cpp -o oo -std=c++11
EOF

output

oo.cpp: In function 'int main()':
oo.cpp:11:10: error: 'thread' is not a member of 'std'
     std::thread t1(threadFunction, 1);
          ^~~~~~
oo.cpp:11:10: note: suggested alternative: 'tera'
     std::thread t1(threadFunction, 1);
          ^~~~~~
          tera
oo.cpp:14:5: error: 't1' was not declared in this scope
     t1.join();
     ^~
oo.cpp:14:5: note: suggested alternative: 'tm'
     t1.join();
     ^~
     tm
@humbertodias humbertodias changed the title c++ std::thread problem ppu-c++ std::thread problem Mar 8, 2024
@humbertodias humbertodias changed the title ppu-c++ std::thread problem ppu-g++ std::thread problem Mar 8, 2024
@StrawFox64
Copy link

something similar to this here

@humbertodias
Copy link
Author

humbertodias commented Mar 18, 2024

It appears that ppu-g++ 13.2.0 lacks support for std::thread.
Consequently, I opted for the traditional C pthread approach as an alternative inside cpp code using extern "C".

Instead of

std::thread t1(threadFunction, 1);

use

pthread_create(&thread_id, nullptr, thread_function, nullptr);

Note

pthread isn't supported natively as well on ps3.
however, luckelly we have a ported version of it here pthread-emb-ps3.

How I did for testing

docker run -i --rm hldtux/ps3dev bash -s <<EOF
echo '#include <iostream>
extern "C" {
#include <pthread.h>
}

void* thread_function(void* arg) {
    std::cout << "Hello from thread\n";
    return nullptr;
}

int main() {
    pthread_t thread_id;
    pthread_create(&thread_id, nullptr, thread_function, nullptr);
    pthread_join(thread_id, nullptr);
    std::cout << "Back in main thread\n";
    return 0;
}' > main.cpp
ppu-g++ main.cpp -o main \
-I/usr/local/ps3dev/portlibs/ppu/include \
-L/usr/local/ps3dev/portlibs/ppu/lib -lpthread
ppu-g++ --version
file main
EOF

output

ppu-g++ (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

main: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, Power ELF V1 ABI, version 1 (SYSV), statically linked, with debug_info, not strippe
d

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

2 participants