4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
31 #include <pulsecore/flist.h>
32 #include <pulsecore/thread.h>
33 #include <pulsecore/log.h>
34 #include <pulsecore/core-util.h>
36 #define THREADS_MAX 20
38 static pa_flist *flist;
41 static void spin(void) {
50 static void thread_func(void *data) {
58 /* Allocate some memory, if possible take it from the flist */
59 if (b && (text = pa_flist_pop(flist)))
60 pa_log("%s: popped '%s'", s, text);
62 text = pa_sprintf_malloc("Block %i, allocated by %s", n++, s);
63 pa_log("%s: allocated '%s'", s, text);
70 /* Give it back to the flist if possible */
71 if (pa_flist_push(flist, text) < 0) {
72 pa_log("%s: failed to push back '%s'", s, text);
75 pa_log("%s: pushed", s);
80 if (pa_flist_push(flist, s) < 0)
84 int main(int argc, char* argv[]) {
85 pa_thread *threads[THREADS_MAX];
88 flist = pa_flist_new(0);
90 for (i = 0; i < THREADS_MAX; i++) {
91 threads[i] = pa_thread_new(thread_func, pa_sprintf_malloc("Thread #%i", i+1));
98 for (i = 0; i < THREADS_MAX; i++)
99 pa_thread_free(threads[i]);
101 pa_flist_free(flist, pa_xfree);