[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6408] Re: lots of Threads

From: "Brian F. Feldman" <green@...>
Date: 2000-11-17 02:04:42 UTC
List: ruby-talk #6408
matz@zetabits.com (Yukihiro Matsumoto) wrote:
> Hi,
> 
> In message "[ruby-talk:6392] Re: lots of Threads"
>     on 00/11/16, hipster <hipster@xs4all.nl> writes:
> 
> |(META: would a pthread impl. of Ruby be a Good Thing[tm]?)
> 
> I really want two things for pthread:
> 
>   * scheme to get list of existing threads
>   * scheme to get stack region addresses for arbitrary thread
> 
> I can make pthread Ruby (especially GC) if I get these.
> 
> 							matz.

You can do something like this.  It will let you always have whatever
info you need...

static VALUE pthreads = Qnil;
/* protect from modification during startup, whatever */
pthread_mutex_t pthread_junk_mutex = PTHREAD_MUTEX_INITIALIZER;

void
rb_pthread_init(void) {

	pthreads = rb_ary_new();
}

void
rb_thread_cleanup(void *me) {
	pthread_mutex_lock(&pthread_junk_mutex);
	pthreads.delete_if {|x|
		*(void **)&x->data[0 * sizeof(void *)] == me
	}
	pthread_mutex_unlock(&pthread_junk_mutex);
	
}


void
rb_pthread_start(struct pthread_startinfo *startinfo) {
	unsigned char threadinfo[2 * sizeof(void *)];
	*(void **)&threadinfo[0 * sizeof(void *)] = pthread_self();
	*(void **)&threadinfo[1 * sizeof(void *)] =
	    pthread_attr_getstackaddr(attr);
	pthread_attr_destroy(startinfo->attr);
	pthread_cleanup_push(rb_thread_cleanup, pthread_self());
	rb_ary_push(pthreads, startinfo.to_struct_etc);
	pthread_mutex_unlock(&pthread_junk_mutex);
	rb_pthread_run(startinfo->block);
	rb_pthread_cleanup(pthread_self());
	pthread_exit(NULL);

VALUE
rb_pthread_new(VALUE self, VALUE block) {
	pthread_attr_t attr;
	/* should specify your own stack policy */
	void *newstack = malloc(STKSIZE);
	newthread = Thread.new();
	pthread_attr_init(&attr);
	pthread_attr_setstacksize(&attr, newstack);
	/* lock here (for thread info), release next when child runs */
	pthread_mutex_lock(&pthread_junk_mutex);
	rb_pthread_start([attr, block, etc.]);
	newthread.do_whatever();
	return (newthread);
}

/* stuff like kill, Thread.list, etc. would need this */
void
rb_pthread_anything_involving_current_state_of_other_threads(...) {
	pthread_mutex_lock(&pthread_junk_mutex);
	do stuff;
	pthread_mutex_unlock(&pthread_junk_mutex);
}

In This Thread