Is it possible to make std::future work?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Is it possible to make std::future work?

Post by kazade »

I'm making progress porting a large library over to KOS, but I've just hit this compiler error:

Code: Select all

scene_manager.h:138:27: error: field 'future' has incomplete type
I've done a bit of digging, and I think it's because the `future` class is hidden behind this ifdef:

Code: Select all

#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) && (ATOMIC_INT_LOCK_FREE > 1)
Before I rip out the use of std::future and replace it with raw threads, I was wondering...

1. Which of those defines is not true on KOS?
2. Is it simple to fix?

Thanks!
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Is it possible to make std::future work?

Post by BlueCrab »

If I had to guess, I'd assume that ATOMIC_INT_LOCK_FREE is not defined, as SuperH doesn't have much in the way of atomic instructions (the only real atomic Read-Modify-Write instruction SuperH has is tas.b). If that's the case, as I presume it is, there's pretty much no way to fix it as it is a limitation of the CPU itself.
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Re: Is it possible to make std::future work?

Post by kazade »

That's exactly what I needed to know, thanks! I've almost finished implementing a syntax-compatible replacement around std::thread and then I can move onto the next compilation error :)
nymus
DC Developer
DC Developer
Posts: 968
Joined: Tue Feb 11, 2003 4:12 pm
Location: In a Dream
Has thanked: 5 times
Been thanked: 6 times

Re: Is it possible to make std::future work?

Post by nymus »

Jut something I noticed about tas.b: Even though it only tests a single byte, the CPU locks and flushes the entire cache line (32 bytes) so if there was a concern about not being able to atomically read/write larger sizes, you could use this information.
behold the mind
inspired by Dreamcast
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1874
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has thanked: 80 times
Been thanked: 61 times
Contact:

Re: Is it possible to make std::future work?

Post by GyroVorbis »

Sorry to bump this ass-ancient thread, but these forums serve largely as a repertoire of information for people searching, and I don't want someone who searches to wind up walking away from this with the wrong impression. Also Kazade is totally still around here. :lol:

We now have BOTH atomics AND std::future working fine with the latest toolchain with the latest version of KOS. The atomics were partially implemented by the compiler and partially by me. The way you can implement them is by disabling interrupts, doing the "atomic operation" then enabling interrupts afterwards. If the scheduler can't preempt the thread, and no interrupts can occur... it's "atomic!" We have them for both C11 and C++11.

Then secondly, yes, std::future works fine now. As does std::async.
These users thanked the author GyroVorbis for the post:
BB Hood
Post Reply