User Tools

Site Tools


os_cp:threads

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
os_cp:threads [2024/04/17 23:28]
jkonczak
os_cp:threads [2024/04/18 11:32]
jkonczak [Accessing the same data from multiple threads]
Line 330: Line 330:
 char text[1020]; char text[1020];
  
-void *updater(void *) {+void *updater(void * arg) {
   while (1)   while (1)
     for (char letter = '​a';​ letter <= '​z';​ ++letter) {     for (char letter = '​a';​ letter <= '​z';​ ++letter) {
Line 343: Line 343:
   pthread_t tid;   pthread_t tid;
   pthread_create(&​tid,​ NULL, updater, NULL);   pthread_create(&​tid,​ NULL, updater, NULL);
-  while (getchar(), 1)+  while (getchar() ​!= EOF)
     printf("​version:​ %llu\n ​  text: %s\n", version, text);     printf("​version:​ %llu\n ​  text: %s\n", version, text);
   return 0;   return 0;
Line 358: Line 358:
 unsigned long long counter; unsigned long long counter;
  
-void *incrementer(void *) {+void *incrementer(void * arg) {
   for (int i = 0; i < 1000; ++i)   for (int i = 0; i < 1000; ++i)
     counter++;     counter++;
os_cp/threads.txt · Last modified: 2024/04/18 11:42 by jkonczak