On Thu, 15 May 2008, Daniel Eischen wrote:I suppose you could also enforce your own scheduling with something like the following: pthread_cond_t writer_cv; pthread_cond_t reader_cv; pthread_mutex_t q_mutex; ... thingy_q_t thingy_q; int writers_waiting = 0; int readers_waiting = 0; ... void enqueue(thingy_t *thingy) { pthread_mutex_lock(q_mutex); /* Insert into thingy q */ ... if (readers_waiting > 0) { pthread_cond_broadcast(&reader_cv, &q_mutex); readers_waiting = 0; } while (thingy_q.size > ENQUEUE_THRESHOLD_HIGH) { writers_waiting++; pthread_cond_wait(&writer_cv, &q_mutex); } pthread_mutex_unlock(&q_mutex); } thingy_t * dequeue(void) { thingy_t *thingy; pthread_mutex_lock(&q_mutex); while (thingy_q.size == 0) { readers_waiting++; pthread_cond_wait(&reader_cv, &q_mutex); } /* Dequeue thingy */ ... if ((writers_waiting > 0) && thingy_q.size < ENQUEUE_THRESHOLD_LOW)) { /* Wakeup the writers. */ pthread_cond_broadcast(&writer_cv, &q_mutex); writers_waiting = 0; } pthread_mutex_unlock(&q_mutex); return (thingy); } The above is completely untested and probably contains some bugs ;-) You probably shouldn't need anything like that if the kernel scheduler is scheduling your threads fairly. -- DE _______________________________________________ freebsd-threads@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-threads To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org"
| Vladislav Bolkhovitin | Re: Integration of SCST in the mainstream Linux kernel |
| Peter Zijlstra | [PATCH 6/6] sched: disabled rt-bandwidth by default |
| Tejun Heo | [PATCHSET] CUSE: implement CUSE |
| Richard Jonsson | forcedeth: MAC-address reversed on resume from suspend |
git: | |
| Junio C Hamano | [0/4] What's not in 1.5.2 (overview) |
| Jan Hudec | Smart fetch via HTTP? |
| Johannes Schindelin | Re: git log filtering |
| Junio C Hamano | [PATCH] combine-diff: reuse diff from the same blob. |
| Julien TOUCHE | setting up ssh tunnel/vpn |
| Jordi Prats | OpenBSD with pf on a mini-ITX? |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| Reyk Floeter | Re: hoststated(8): DNS Relay uses unexpected source IP address |
| David Miller | Re: [ANNOUNCE] Btrfs v0.12 released |
| Christophe Saout | Re: silent semantic changes with reiser4 |
| Anton Altaparmakov | Re: [RFC] add FIEMAP ioctl to efficiently map file allocation |
| Rik van Riel | Re: [RFD] Incremental fsck |
