示例#1
0
static noreturn void thread_entry(cloudabi_tid_t tid, void *data) {
  // Set up TLS space.
  char tls_space[tls_size()];
  char *tls_start = tls_addr(tls_space);
  memcpy(tls_start, __pt_tls_vaddr_abs, __pt_tls_filesz);
  memset(tls_start + __pt_tls_filesz, '\0',
         __pt_tls_memsz_aligned - __pt_tls_filesz);
  tls_replace(tls_space);

  // Fix up some of the variables stored in TLS.
  pthread_t handle = data;
  __pthread_self_object = handle;
  __pthread_thread_id = tid;
  __safestack_unsafe_stack_ptr = (void *)__rounddown(
      (uintptr_t)handle->unsafe_stack + handle->unsafe_stacksize,
      PTHREAD_UNSAFE_STACK_ALIGNMENT);

  // Initialize the the once object used for joining. This is also done
  // by the parent, but it may be the case that we call pthread_exit()
  // before the parent has a chance to initialize it.
  cloudabi_lock_t expected = CLOUDABI_LOCK_BOGUS;
  atomic_compare_exchange_strong_explicit(
      &handle->join, &expected, tid | CLOUDABI_LOCK_WRLOCKED,
      memory_order_acquire, memory_order_relaxed);

  // Free thread startup information and invoke user-supplied start routine.
  void *(*start_routine)(void *) = handle->start_routine;
  void *argument = handle->argument;
  pthread_exit(start_routine(argument));
}
void wrapper(void* (*start_routine)(void*), void *arg)
{
    void *retval;
    retval = (void *) start_routine(arg);  
    gtthread_exit(retval);
    return;
}
示例#3
0
static gsize WINAPI
inner_start_thread (gpointer data)
{
	CreateThreadData *thread_data;
	MonoThreadInfo *info;
	MonoThreadStart start_routine;
	gpointer start_routine_arg;
	gsize start_routine_res;
	gsize dummy;

	thread_data = (CreateThreadData*) data;
	g_assert (thread_data);

	start_routine = thread_data->start_routine;
	start_routine_arg = thread_data->start_routine_arg;

	info = mono_thread_info_attach (&dummy);
	info->runtime_thread = TRUE;

	thread_data->handle = mono_threads_open_thread_handle (info->handle);

	mono_coop_sem_post (&thread_data->registered);

	mono_refcount_dec (thread_data);

	/* thread_data is not valid anymore */
	thread_data = NULL;

	/* Run the actual main function of the thread */
	start_routine_res = start_routine (start_routine_arg);

	mono_thread_info_exit (start_routine_res);

	g_assert_not_reached ();
}
示例#4
0
void run_thread(void *(*start_routine)(void *), void *arg)
{
	void *rv; 
	sigprocmask(SIG_UNBLOCK, &alrm, NULL);

	rv = start_routine(arg);
	gtthread_exit(rv);
}
示例#5
0
static void* set_affinity_trampoline(void* arg) {
  struct affinity_trampoline* trampoline = arg;
  sched_setaffinity(0, sizeof(cpu_set_t), &trampoline->cpuset);
  void* trampoline_arg = trampoline->arg;
  void* (*start_routine)(void*) = trampoline->start_routine;
  free(trampoline);
  return start_routine(trampoline_arg);
}
示例#6
0
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) {
  static int warn = 1;
  if (warn) {
    fprintf(stderr, "Sulong does not support threads yet, using pthread stub!\n");
    warn = 0;
  }
  start_routine(arg);
  return 0;
}
示例#7
0
static void start_wrapper(void *(*start_routine)(void *), void *arg) {
  void *retval;

  /* Unblock alarms */
  sigprocmask(SIG_UNBLOCK, &vtalrm, NULL);

  retval = start_routine(arg);
  gtthread_exit(retval);
}
示例#8
0
static unsigned __stdcall win32_start_routine(void *arg)
{
    QemuThreadData *data = (QemuThreadData *) arg;
    void *(*start_routine)(void *) = data->start_routine;
    void *thread_arg = data->arg;

    qemu_thread_data = data;
    qemu_thread_exit(start_routine(thread_arg));
    abort();
}
示例#9
0
int 
ldap_pvt_thread_create( ldap_pvt_thread_t * thread, 
	int detach,
	void *(*start_routine)(void *),
	void *arg)
{
	if( ! detach ) ldap_int_status = NULL;
	start_routine( arg );
	return 0;
}
示例#10
0
/* Wrapper function for start_routine of pthread_create() */
static void *wrapper(void *warg) {
  // Initialize malloc library for this thread
  sf_malloc_thread_init();
  // Get the routine and argument for the pthread_create
  start_fpt start_routine = ((wrapper_arg_t *)warg)->start_fun;
  void *arg = ((wrapper_arg_t *)warg)->arg;
  free(warg);
  void *result = start_routine(arg);
  return result;
}
示例#11
0
// using separate function avoid unnecessary copies of local variables
// from functions invoking pthread_create, don't inline!
void __actual_thread_spawn(
  void * (*start_routine)(void *),
  void *arg,
  unsigned long id)
{
  __CPROVER_HIDE:;
  __CPROVER_ASYNC_1: __CPROVER_thread_id=id,
                       start_routine(arg),
                       __CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence",
                                       "WWcumul", "RRcumul", "RWcumul", "WRcumul"),
                       __CPROVER_threads_exited[id]=1;
}
示例#12
0
文件: create.c 项目: GYGit/reactos
static void __threadentry (void *(*start_routine)(void*), void *arg)
{
 INFO("hello world! thread successfully created");

 TODO("initialize thread data");
 TODO("notify DLLs");
 TODO("notify psxss");

 INFO("about to call start routine at %#x with argument %#x", start_routine, arg);

 pthread_exit(start_routine(arg));
}
示例#13
0
/* The entry-point for new threads.  */
static void
entry_point (void *(*start_routine)(void *), void *arg)
{
#ifdef HAVE_USELOCALE
  /* A fresh thread needs to be bound to the global locale.  */
  uselocale (LC_GLOBAL_LOCALE);
#endif

  __pthread_startup ();

  pthread_exit (start_routine (arg));
}
示例#14
0
static void* wrapper_routine(void* data)
{
    void* (*start_routine)(void*) = ((wrapper_t*)data)->start_routine;
    void* arg = ((wrapper_t*)data)->arg;

    setitimer(ITIMER_PROF, &((wrapper_t*)data)->itimer, NULL);

    pthread_mutex_lock(&((wrapper_t*)data)->lock);
    pthread_cond_signal(&((wrapper_t*)data)->cond);
    pthread_mutex_unlock(&((wrapper_t*)data)->lock);

    fprintf(stderr, "pthread wrapper, start real routine\n");
    return start_routine(arg);
}
static unsigned __stdcall win32_start_routine(void *arg)
{
    QemuThreadData *data = (QemuThreadData *) arg;
    void *(*start_routine)(void *) = data->start_routine;
    void *thread_arg = data->arg;

    if (data->mode == QEMU_THREAD_DETACHED) {
        g_free(data);
        data = NULL;
    }
    qemu_thread_data = data;
    qemu_thread_exit(start_routine(thread_arg));
    abort();
}
示例#16
0
文件: process.c 项目: alohays/mylysos
//Init 쓰레드의 핸들러 함수
static void PspTaskEntryPoint(void)
{
	PKSTART_ROUTINE start_routine;
	HANDLE current_thread;
	DWORD ret_value;

	current_thread = PsGetCurrentThread();
	start_routine = PsGetThreadPtr(current_thread)->start_routine;
	ret_value = start_routine(PsGetThreadPtr(current_thread)->start_context);

	PsGetThreadPtr(current_thread)->thread_status = THREAD_STATUS_TERMINATED;
	HalTaskSwitch();

	while(1) ;
}
/* The wrapper function in charge for setting the itimer value */
static void * wrapper_routine(void * data)
{
  /* Put user data in thread-local variables */
  void * (*start_routine)(void *) = ((wrapper_t*)data)->start_routine;
  void * arg = ((wrapper_t*)data)->arg;

  /* Set the profile timer value */
  setitimer(ITIMER_PROF, &((wrapper_t*)data)->itimer, NULL);

  /* Tell the calling thread that we do not need its data anymore */
  pthread_mutex_lock(&((wrapper_t*)data)->lock);
  pthread_cond_signal(&((wrapper_t*)data)->wait);
  pthread_mutex_unlock(&((wrapper_t*)data)->lock);

  /* Call the real function */
  return start_routine(arg);
}
示例#18
0
void *threadStartFunc(void *data){
  /*This looks weird, but it sets the value associated with dkey to 0x1
   *  forcing thd_dtr() to run when the thread terminates.  */
  pthread_setspecific(dkey,(void*)0x1);

#ifdef IFRIT_ARRAY
  curWIFRVar = 0;
  curRIFRVar = 0;
  maxWIFRVar = INIT_ACTIVE;
  maxRIFRVar = INIT_ACTIVE;
  myWIFRVars = (unsigned long *) malloc(INIT_ACTIVE * sizeof(unsigned long));
  myRIFRVars = (unsigned long *) malloc(INIT_ACTIVE * sizeof(unsigned long));
#endif

#ifdef IFRIT_HASH_TABLE
  myWriteIFRs = g_hash_table_new(g_direct_hash, g_direct_equal);
  myReadIFRs = g_hash_table_new(g_direct_hash, g_direct_equal);
#endif

  pthread_mutex_lock(&allThreadsLock);
  int i = 0;
  for(i = 0; i < MAX_THDS; i++){
    if( allThreads[i] == (pthread_t)0 ){
      allThreads[i] = pthread_self();
      break;
    }
  }

#ifdef SINGLE_THREADED_OPT
  num_threads++;
#endif

  pthread_mutex_unlock(&allThreadsLock);

  raceCheckIFR = new_ifr(pthread_self(), 0, 0, 0);

#ifdef PROGRAM_POINT_OPT
  PCTable = g_hash_table_new(g_direct_hash, g_direct_equal);
#endif

  void *(*start_routine)(void*) = ((threadInitData *)data)->start_routine;
  void *arg = ((threadInitData *) data)->arg;
  free(data);
  return (start_routine(arg));
}
示例#19
0
static void* NVThreadSpawnProc(void* arg)
{
	NVThreadInitStruct* init = (NVThreadInitStruct*)arg;
	void *(*start_routine)(void *) = init->m_startRoutine;
	void* data = init->m_arg;
	void* ret;

	free(arg);

	NVThreadGetCurrentJNIEnv();

	ret = start_routine(data);

	if (s_vm)
		(*s_vm)->DetachCurrentThread(s_vm);

	return ret;
}
示例#20
0
文件: override.c 项目: aclements/sv6
static void *
wrapper(void *wargs)
{
    void *result;
    start_fun_t start_routine = ((wrapper_args_t *) wargs)->app_start;
    void *arg = ((wrapper_args_t *) wargs)->app_arg;

    thread_id = atmc_fetch_and_add(&global_id_counter, 1);

#ifdef NUMA
    //discover_cpu();
#endif

    munmap(wargs, sizeof(wrapper_args_t));
    result = start_routine(arg);
    streamflow_thread_finalize();

    return result;
}
示例#21
0
static gsize WINAPI
inner_start_thread (gpointer data)
{
	CreateThreadData *thread_data;
	MonoThreadInfo *info;
	MonoThreadStart start_routine;
	gpointer start_routine_arg;
	guint32 start_routine_res;
	gint32 priority;
	gsize dummy;

	thread_data = (CreateThreadData*) data;
	g_assert (thread_data);

	start_routine = thread_data->start_routine;
	start_routine_arg = thread_data->start_routine_arg;

	priority = thread_data->priority;

	info = mono_thread_info_attach (&dummy);
	info->runtime_thread = TRUE;

	mono_threads_platform_set_priority (info, priority);

	thread_data->handle = mono_thread_info_duplicate_handle (info);

	mono_coop_sem_post (&thread_data->registered);

	if (InterlockedDecrement (&thread_data->ref) == 0) {
		mono_coop_sem_destroy (&thread_data->registered);
		g_free (thread_data);
	}

	/* thread_data is not valid anymore */
	thread_data = NULL;

	/* Run the actual main function of the thread */
	start_routine_res = start_routine (start_routine_arg);

	mono_threads_platform_exit (start_routine_res);

	g_assert_not_reached ();
}
示例#22
0
inline int pthread_create(
  pthread_t *thread,
  const pthread_attr_t *attr,
  void * (*start_routine)(void *),
  void *arg)
{
  __CPROVER_HIDE:;
  unsigned long this_thread_id;
  __CPROVER_atomic_begin();
  this_thread_id=++__CPROVER_next_thread_id;
  __CPROVER_atomic_end();

  if(thread)
  {
    #ifdef __APPLE__
    // pthread_t is a pointer type on the Mac
    *thread=(pthread_t)this_thread_id;
    #else
    *thread=this_thread_id;
    #endif
  }

  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
  __CPROVER_set_must(thread, "pthread-id");
  #endif

  if(attr) (void)*attr;

  __CPROVER_ASYNC_1:
    __CPROVER_thread_id=this_thread_id,
    #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
    // Clear all locked mutexes; locking must happen in same thread.
    __CPROVER_clear_must(0, "mutex-locked"),
    __CPROVER_clear_may(0, "mutex-locked"),
    #endif
    start_routine(arg),
    __CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence",
                    "WWcumul", "RRcumul", "RWcumul", "WRcumul"),
    __CPROVER_threads_exited[this_thread_id]=1;

  return 0;
}
/* Wrapper de la routine appelé par pthread_create */
static void * wrapper_routine(void * data) {
    /* Put user data in thread-local variables */ 
    void * (*start_routine)(void *) = ((wrapper_t*)data)->start_routine; 
    void * arg = ((wrapper_t*)data)->arg; 

        pthread_mutex_lock(&inside);
        // tid = hashid.processes[id(pthread_self())];
        // assert(tid != NULL);
        VERBOSE("[INTERCEPT] --> SET TLS (%d)\n", tid->id);
        pthread_mutex_unlock(&inside);
       
        /* Tell the calling thread that we don't need its data anymore */ 
        pthread_mutex_lock(&((wrapper_t*)data)->lock); 
        pthread_cond_signal(&((wrapper_t*)data)->wait); 
        pthread_mutex_unlock(&((wrapper_t*)data)->lock);
       
    /* Call the real function */
    //  assert(arg != NULL);   
    return start_routine(arg); 
}
示例#24
0
void		be_hungry(t_philo *philo)
{
  if (sem_wait(&philo->fork_s))
    {
      fprintf(stderr, "%s\n", ERROR_SEM_WAIT);
      exit(EXIT_FAILURE);
    }
  philo->state = HUNGRY;
  philo->fork = UNAVAILABLE;
  if (sem_post(&philo->fork_s))
    {
      fprintf(stderr, "%s\n", ERROR_SEM_POST);
      exit(EXIT_FAILURE);
    }
  sleep(HUNGRY_TIME);
  if (get_fork_val(philo->next))
    you_eat(philo);
  else
    start_routine(philo);
}
void WrapperFunction(void*(*start_routine)(void *), void* arg){
	void *returnval;
	dlink_t* temp_dlink;

	returnval = start_routine(arg);

	BlockSignals();
	//Need to fire a new thread
	schedule_queue->running->thread_block->finished =1;
	schedule_queue->running->thread_block->returnval = returnval;
	temp_dlink = FindNode(schedule_queue,schedule_queue->running->thread_block->parent_threadid);
	if(temp_dlink == NULL){
		fprintf(stderr,"gtthread_exit() error: no parent found");
		exit(1);
	}
	else{
		temp_dlink->thread_block->child_count--;
		UnblockSignals();
		raise(SIGVTALRM);
	}
}
示例#26
0
int main(void)
{
#ifndef PTEST_USE_THREAD
    start_routine(0);
#else
    pthread_t th;
    int i, status;

    add1(0, 0);   /* this is the main thread */

    remaining = PTEST_USE_THREAD;
    for (i = 0; i < PTEST_USE_THREAD; i++) {
        status = pthread_create(&th, NULL, start_routine, NULL);
        assert(status == 0);
    }
    pthread_mutex_lock(&mutex1);
    while (remaining)
        pthread_cond_wait(&cond1, &mutex1);
    pthread_mutex_unlock(&mutex1);
#endif
    return 0;
}
示例#27
0
void* start_routine_wrapper(void *arg) {
  pthread_t self = pthread_self();
  start_routine_t start_routine;

retry:
  {
  Lock lock(m_threadmap_lock);

  auto it = threadMap.find(self);
  if (it == threadMap.end()) {
    goto sleep_wait;
  }

  auto& info = it->second;
  MemoryManager::TlsWrapper::getCheck();
  info.mm = &MM();
  assert(info.mm);
  info.mm->resetExternalStats();
#ifdef __linux__
  info.tid = syscall(SYS_gettid);
#else
  info.tid = getpid();
#endif
  info.pid = getpid();
  start_routine = info.start_routine;
  goto done;
  }

sleep_wait:
  usleep(100);
  goto retry;

done:
  auto ret = start_routine(arg);
  log_pthread_event(PTHREAD_EXIT, &self);
  return ret;
}
示例#28
0
void run(void *(*start_routine)(void *),void *arg){
	curr->running=1;
    curr->ret_val=start_routine(arg);
	curr->completed=1;
	while(1);
}
示例#29
0
void QtThread::run()
{
    start_routine(pointer);
}
示例#30
0
/* Adapter to translate Unix thread start routines to Windows thread start
 * routines.
 */
static DWORD WINAPI
sctp_create_thread_adapter(void *arg) {
	start_routine_t start_routine = (start_routine_t)arg;
	return start_routine(NULL) == NULL;
}