After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 433314 - GSlice multithreaded thread allocation test
GSlice multithreaded thread allocation test
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-04-25 14:41 UTC by Stefan Westerfeld
Modified: 2007-07-12 22:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The actual test code (2.79 KB, text/x-csrc)
2007-04-25 14:47 UTC, Stefan Westerfeld
Details

Description Stefan Westerfeld 2007-04-25 14:41:29 UTC
While searching a bug in beast, I assumed that maybe GSlice would get confused when memory was allocated in a thread and freed in another frequently. To prove that this wouldn't be the problem, I wrote a test program (which revealed no problems in GSlice). However it may be useful to put this in the glib test suite.
Comment 1 Stefan Westerfeld 2007-04-25 14:47:36 UTC
Created attachment 86993 [details]
The actual test code

Can be compiled with:

gcc -g -Wall -O3 -o gmt gmt.c $(pkg-config --cflags --libs gthread-2.0)
Comment 2 Tim Janik 2007-07-12 15:43:48 UTC
thanks, test case added. however, i had to rework the usleep() statements which together accumulated to really long test runs, which is a no-no for unit tests:
  http://blogs.gnome.org/timj/2006/10/23/23102006-beast-and-unit-testing/

and also, sleeps don't properly force rescheduling across all uni-processor AND multi-core scenarios. that's because depending on UP/SMP, thread load and thread interaction, you might need to sleep or sched_yield(), often it's hard to tell which. so i've resorted to seldom randomized sleep vs. sched_yield now, which shoud amortize to good concurrent execution on any UP/SMP scenario and shouldn't idle for 99+% of the execution time:

      /* shuffle thread execution order every once in a while */                                                                                              
      if (rand() % 97 == 0)                                                                                                                                   
        {                                                                                                                                                     
          if (rand() % 2)                                                                                                                                     
            g_thread_yield();   /* concurrent shuffling for single core */                                                                                    
          else                                                                                                                                                
            g_usleep (1000);    /* concurrent shuffling for multi core */                                                                                     
        }                                                                                                                                                    
Comment 3 Stefan Westerfeld 2007-07-12 22:26:44 UTC
Your changes look fine to me. The execution order may become a bit "less random", but probably still good enough to preserve the spirit of the test. The only other idea I had after seeing your changes was be to precompute the desired execution order and force the necessary context switches, but then again, that would make the aspect of the test that it stresses concurrent access to g_slice disappear.