Jump to content

Talk:Pthreads

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

interix not native

[edit]

I believe from the following: "The Interix Pthread implementation is built upon the thread functionality already provided by the Windows kernel. " from http://technet.microsoft.com/en-us/library/bb463209.aspx#EEAA that the interix implementation is a wrapper as much as the other windows implementations. If nobody corrects me here in a week or two I'll go ahead and update it as such. Rogerdpack (talk) 04:59, 22 July 2012 (UTC)[reply]

use of rand()

[edit]

Running the sample code on cygwin in windows, the rand() function seems to have the same seed value in each thread that it's called in, meaning that I always get a 4 second sleep for every thread. Is this specific to my environment? I'm not much of a C programmer, so won't edit the page directly, but perhaps a good change would be to seed based on time in main() and then pass the sleep value as another argument to each thread initialisation, or keep it a bit more noddy and write which will at least give some different values for each thread.

  int sleep_time =  (index * 3) % NUM_THREADS;

Example description slightly incorrect?

[edit]

In the description of the example it is stated: "If a programmer wanted the threads to communicate with each other, this would require defining a variable outside of the scope of any of the functions, making it a global variable."

This seems to be incorrect? Whatever function is starting the thread could pass a more complex structure as thread_args, there is no need for global variables in the way that term is normally used in C (a variable declared outside the scope of any function.) --Lasse Hillerøe Petersen (talk) 12:25, 5 April 2020 (UTC)[reply]

Use of rand() in multiple threads

[edit]

Isn't rand() thread unsafe? Use rand_r() instead if it is. The example program seems a bit off. A good (though long) example program can be found here: https://man7.org/linux/man-pages/man3/pthread_create.3.html