Beispiel #1
0
int Thread::destroy(int64_t id) {
    if(id == thread_self->id || id==main_threadid)
        return 1; // cannot destroy thread_self or main

    Thread* thread = getThread(id);
    if(thread == NULL || thread->daemon)
        return 1;

    if (thread->state == THREAD_KILLED || thread->terminated)
    {
        if (thread->id == main_threadid)
        {
            return 3; // should never happen
        }
        else
        {
            popThread(thread);
            thread->term();
            std::free (thread);
            return 0;
        }
    } else {
        return 2;
    }
}
int main()
{
  std::thread pushThread(push);
  std::thread popThread(pop);

  if(pushThread.joinable())
    pushThread.join();

  if(popThread.joinable())
    popThread.join();

  return 0;
}
Beispiel #3
0
/**
 * this is an escalonator, operator() para o asio
 */
void JavaVM::execThreads() //Each thread needs to have his stack
{
	StackFrame * currentThread = NULL;
	while(true) //TODO while this program is alive, for asio remove it
	{
		currentThread = popThread();
		if(currentThread == NULL)
			continue; //need to be async, e criar isso sendo algo para o boost::asio

		if (execThread(currentThread, 2000))
		{
			pushThread(currentThread);
		}
		else
		{
			//this thread's done
		}
	}
}