multithreading - Multi-Threading Issue in C -


i'm trying out multi-threading in c first time, , seem doing wrong hope me with. here code:

#include "stdafx.h"  #define max_threads 2   int a[100000]; int b[200000];  void startthreads();  dword winapi populatearraya(lpvoid data) {     int i;     int* pa = (int*)data;      for(i = 0; < sizeof(a) / sizeof(int); i++)     {         *pa = i;         pa++;     }      return 0; } dword winapi populatearrayb(lpvoid data) {     int i;     int* pb = (int*)data;      for(i = 0; < sizeof(b) / sizeof(int); i++)     {         *pb = i;         pb++;     }     return 0; }  void startthreads() {     handle threads[max_threads];     dword  threadids[max_threads];      threads[0] = createthread(null,0,populatearraya,a,0,&threadids[0]);     threads[1] = createthread(null,0,populatearrayb,b,0,&threadids[1]);      if(threads[0] && threads[1])     {         printf("threads created. (ids %d , %d)",threadids[0],threadids[1]);     }      waitformultipleobjects(max_threads,threads,true,0);  }  int main(int argc, char* argv[]) {     int i;      memset(a,0,sizeof(a));     memset(b,0,sizeof(b));      startthreads();      return 0; } 

in code, array "b" seems populate fine, array "a" not. sorry if answer stupid!

edit: tried again, , both arrays '0's. not quite sure what's going on. i'm using visual studio in case it's debugging issue or something.

cheers.

the last parameter of waitformultipleobjects must infinite, not 0. 0, function returns immediatly.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -