Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
83 user(s) are online (53 user(s) are browsing Forums)

Members: 1
Guests: 82

orgin, more...

Headlines

 
  Register To Post  

GCC: pthread threading instead of native threading
Home away from home
Home away from home


See User information
@All

As currently native implementation of threading support in our GCC have some bugs:

https://github.com/sba1/adtools/issues/76
https://github.com/sba1/adtools/issues/82

And that can take "2 more weeks" for them to be fixed, Sebastian suggest that for time being phtread threading can be used.

But there i need some help from skilled devs as well.

So, we do have for pthread threading implementation a file caleld "gthr-amigaos-posix.c":

https://github.com/sba1/adtools/blob/7 ... -thread-model.patch#L1319

There is whole file out of patch from my adtools build:

/**
 * This is the posix.libraray-based implementation of gcc threads abstraction.
 */

#include "gthr-amigaos.h"

#include <pthread.h>
#include <proto/exec.h>

#ifdef __cplusplus
extern "C"
{
#endif

/******************************************************************************/

typedef struct
{
  
union
  
{
    
__gthread_once_t gonce;
    
pthread_once_t ponce;
  } 
u;
__internal_gthread_once_t;

typedef struct
{
  
union
  
{
    
__gthread_mutex_t gmutex;
    
pthread_mutex_t pmutex;
  } 
u;
__internal_gthread_mutex_t;

typedef struct
{
  
union
  
{
    
__gthread_cond_t gcond;
    
pthread_cond_t pcond;
  } 
u;
__internal_gthread_cond_t;


/******************************************************************************/

#include "gthr-amigaos-asserts.h"

/******************************************************************************/

int
__gthread_active_p 
(void)
{
  
/* Thread-system is always active as we have to be explicitly linked to the
   * final binary.
   */
  
return 1;
}

int
__gthread_once 
(__gthread_once_t *__oncevoid (*__func) (void))
{
  
__internal_gthread_once_t *once = (__internal_gthread_once_t *)__once;

  if (
__gthread_active_p ())
    return 
pthread_once (&once->u.ponce__func);
  else
    return -
1;
}

int
__gthread_key_create 
(__gthread_key_t *__keyvoid (*__func) (void *))
{
  
int err;
  
pthread_key_t key;

  if ((
err pthread_key_create (&key__func)))
    return 
err;
  
__key->id key;
  return 
0;
}

int
__gthread_key_delete 
(__gthread_key_t __key)
{
  return 
pthread_key_delete (__key.id);
}

void *
__gthread_getspecific (__gthread_key_t __key)
{
  return 
pthread_getspecific (__key.id);
}

int
__gthread_setspecific 
(__gthread_key_t __key, const void *__v)
{
  return 
pthread_setspecific (__key.id__v);
}

int
__gthread_mutex_init 
(__gthread_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  return 
pthread_mutex_init (&mx->u.pmutex0);
}

int
__gthread_mutex_destroy 
(__gthread_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  return 
pthread_mutex_destroy (&mx->u.pmutex);
}

int
__gthread_mutex_lock 
(__gthread_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  return 
pthread_mutex_lock (&mx->u.pmutex);
}

int
__gthread_mutex_trylock 
(__gthread_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  return 
pthread_mutex_trylock (&mx->u.pmutex);
}

int
__gthread_mutex_unlock 
(__gthread_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  return 
pthread_mutex_unlock (&mx->u.pmutex);
}

int
__gthread_recursive_mutex_init 
(__gthread_recursive_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;

  
pthread_mutexattr_t attr;
  
int err;

  if ((
err pthread_mutexattr_init (&attr)))
    return 
err;
  if ((
err pthread_mutexattr_settype (&attrPTHREAD_MUTEX_RECURSIVE)))
    goto 
bailout;
  if ((
err pthread_mutex_init (&mx->u.pmutex, &attr)))
    goto 
bailout;
  return 
pthread_mutexattr_destroy (&attr);
bailout:
  
pthread_mutexattr_destroy (&attr);
  return 
err;
}

int
__gthread_recursive_mutex_lock 
(__gthread_recursive_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;
  return 
pthread_mutex_lock (&mx->u.pmutex);
}

int
__gthread_recursive_mutex_trylock 
(__gthread_recursive_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;
  return 
pthread_mutex_trylock (&mx->u.pmutex);
}

int
__gthread_recursive_mutex_unlock 
(__gthread_recursive_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;
  return 
pthread_mutex_unlock (&mx->u.pmutex);
}

int
__gthread_recursive_mutex_destroy 
(__gthread_recursive_mutex_t *__mutex)
{
  
__internal_gthread_mutex_t *mx = (__internal_gthread_mutex_t *)__mutex;
  return 
pthread_mutex_destroy (&mx->u.pmutex);
}

int
__gthread_create 
(__gthread_t *threadvoid *(*func) (void*), void *args)
{
  
int err;
  
pthread_t pthread;

  if ((
err =  pthread_create (&pthreadNULLfuncargs)))
    return 
err;
  *
thread pthread;
  return 
0;
}

int
__gthread_join 
(__gthread_t threadvoid **value_ptr)
{
  return 
pthread_join (threadvalue_ptr);
}

int
__gthread_detach 
(__gthread_t thread)
{
  return 
pthread_detach (thread);
}

int
__gthread_equal 
(__gthread_t t1__gthread_t t2)
{
  return 
pthread_equal (t1t2);
}

__gthread_t __gthread_self (void)
{
  return 
pthread_self ();
}

int
__gthread_yield 
(void)
{
  
IExec->Reschedule();
  return 
0;
}

#ifdef __cplusplus
}
#endif



Now,i take that test case:

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

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


And compile it like this:

g++ test.cpp gthr-amigaos-posix.c -o test -lpthread

It compiles, but then on start, it crashes with stack trace point out on "pthread_key_create()" as function in which it crashes. Disassembly show "lwz r0, 228(r9)", and r9 are 0x00000000.

That happens even before I have "before" word. Ignore DSI help, and then it printf me "before" and "after" words, and crashes again on exit, this time in pthread_getspecific(), which can be a side effect of first crash, or very possible the same issues why test case fail on native-threading implementation...

Sebastian suggest that maybe some lib is not openend properly or, of course, something else can be missing in the implementation.

Any ideas-suggestions are welcome !

Of course, will be much better to fix those 2 bugs in native threading implementation, which is there:

https://github.com/sba1/adtools/blob/7 ... s-thread-model.patch#L300

But i assume it can be harder than pthreads ones ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GCC: pthread threading instead of native threading
Home away from home
Home away from home


See User information
Tried to find maybe it's needs to manually open pthreads.library, but then in our SDK we don't have any inlines/interfaces/etc for pthreads.library, only pure "pthread.h" without anything amiga specific, and link libs. So probabaly that not it.

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-2023 The XOOPS Project