Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
49 user(s) are online (41 user(s) are browsing Forums)

Members: 1
Guests: 48

orgin, more...
Support us!
Recent OS4 Files
OS4Depot.net





how to replace std::this_thread::get_id()
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 5529
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("beforen");
    
std::thread::id id std::this_thread::get_id();
    
printf("aftern");
}


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("beforen");
    
std::thread::id id = (std::thread::id)IExec->FindTask(NULL);
    
printf("aftern");
}


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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: how to replace std::this_thread::get_id()
Quite a regular
Joined:
2007/7/14 20:30
From Lothric
Posts: 803
@kas1e

Try:

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

   Report Go to top

Re: how to replace std::this_thread::get_id()
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 5529
@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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: how to replace std::this_thread::get_id()
Just can't stay away
Joined:
2006/11/30 11:30
From Finland
Posts: 1689
@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.

   Report Go to top

Re: how to replace std::this_thread::get_id()
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 5529
@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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top

Re: how to replace std::this_thread::get_id()
Just can't stay away
Joined:
2006/11/30 11:30
From Finland
Posts: 1689
@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.

   Report Go to top

Re: how to replace std::this_thread::get_id()
Quite a regular
Joined:
2013/10/17 15:21
From Hungary
Posts: 600
@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.

_________________
I see the jimmies have been rustled.
   Report Go to top

Re: how to replace std::this_thread::get_id()
Quite a regular
Joined:
2007/7/14 20:30
From Lothric
Posts: 803
@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 */ });

   Report Go to top

Re: how to replace std::this_thread::get_id()
Home away from home
Joined:
2007/9/11 11:31
From Russia
Posts: 5529
@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!
zerohero's mirror of os4/os3 crosscompiler suites
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project