Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
141 user(s) are online (123 user(s) are browsing Forums)

Members: 1
Guests: 140

billyfish, more...

Support us!

Headlines

 
  Register To Post  

how to replace std::this_thread::get_id()
Home away from home
Home away from home


See User information
Lately found that this simple piece of code just crashes on the our latest compiler with -athread=native:

#include <stdio.h>
#include <string>
#include <thread>

int main()
{
    
printf("before\n");
    
std::thread::id id std::this_thread::get_id();
    
printf("after\n");
}


Which mean, that this is not implemented or didn't handled correctly in adtools repo. Will be it fixed or not, for now pretty hard to say, as there i didn't see any sign that bugs also fixed in adtool's repo: there just keeps collecting lots of bug-reports which didn't taken in account, and all what we report in last year seems didn't fixed.

So, question is, is there possiblity to somehow use my own code inside of this std::this_thread::get_id(), so implementing this will works in all other's code which use it as expected ?

Sebastian says that probabaly i can use there FindTask(NULL), so i tried it like this:


#include <stdio.h>
#include <string>
#include <thread>

int main()
{
    
printf("before\n");
    
std::thread::id id = (std::thread::id)IExec->FindTask(NULL);
    
printf("after\n");
}


So for first it give a error "error: invalid conversion from ‘Task*’ to ‘std::thread::native_handle_type’ {aka ‘int’} [-fpermissive]" , and then when i use -fpermissive it compiles and _maybe_ works (at least it print some value), but compiles with warnings.

Is anyone have any idea how to deal with without errors, and , what is more important for easy porting process, so without needs to doing much changes in the game's code itself ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: how to replace std::this_thread::get_id()
Just can't stay away
Just can't stay away


See User information
@kas1e

Try:

std::thread::id id = reinterpret_cast<std::thread::id>(FindTask(NULL));

Go to top
Re: how to replace std::this_thread::get_id()
Home away from home
Home away from home


See User information
@Capehill

cat test.cpp

#include <stdio.h>
#include <string>
#include <thread>
#include <proto/exec.h>

int main()
{
    
printf("beforen");
    
std::thread::id id reinterpret_cast<std::thread::id>(IExec->FindTask(NULL));
    
printf("aftern");
}


ppc-amigaos-g++ -athread=native test.cpp -o test -lauto
test
.cppIn function ‘int main():
test.cpp:9:81errorinvalid cast from type ‘Task*’ to type ‘std::thread::id’
     std
::thread::id id reinterpret_cast<std::thread::id>(IExec->FindTask(NULL));
                                                                                 ^



I asked Sebastian what it can be , some unimplemented feature or a bug, he says that everything possible, but he point out on that file where all that works about thread done:

https://github.com/sba1/adtools/blob/m ... migaos-thread-model.patch

He this fix should be easy one, and his bet is that some part of __gthread_self() is missing so that the master task should also be taken into account.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: how to replace std::this_thread::get_id()
Just can't stay away
Just can't stay away


See User information
@kas1e

Unless you need to support tasks for some reason, it is better if you use getpid() (or IDOS->GetPID(NULL, GPID_PROCESS)) instead of IExec->FindTask(NULL).

It returns a numeric ID for the current process that is guaranteed to be unique and is supposed to be used for this purpose.

Go to top
Re: how to replace std::this_thread::get_id()
Home away from home
Home away from home


See User information
@salas00
Yeah, getpid() works without warnings and errors, cool!

Can i somehow reassign std::this_thread::get_id(); , so when that line called , get_id() will be just getpid(), but will works from the same std::this_thread:: , and i will have no needs to add hundreds ifdefs all over the code (so just overload that function somewhere in one place which is included everywhere).

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: how to replace std::this_thread::get_id()
Just can't stay away
Just can't stay away


See User information
@kas1e

Since get_id() is defined as an inline function with code directly in the <thread> header file I don't think it can be replaced without modifying the header file itself.

Go to top
Re: how to replace std::this_thread::get_id()
Quite a regular
Quite a regular


See User information
@salass00
I don't think any of the std::thread functions take ids as an argument, so getpid should be OK for getting a unique id for the current thread.

This is just like television, only you can see much further.
Go to top
Re: how to replace std::this_thread::get_id()
Just can't stay away
Just can't stay away


See User information
@kas1e

Maybe you could try to create one dummy thread before calling the first std::this_thread::get_id(), assuming that the problem is that some initialization is done only when some sub-thread is created.

This is again non-tested code:

Quote:

std::async(std::launch::async, []{ /* Nothing here */ });

Go to top
Re: how to replace std::this_thread::get_id()
Home away from home
Home away from home


See User information
@Capehill
That one didn't crashes, but when i add prinfs to see actual id, i have : "thread::id of a non-executing thread".

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project