Search Results

Search found 4 results on 1 pages for 'sergiobuj'.

Page 1/1 | 1 

  • Multiple threads or process with threads

    - by sergiobuj
    Hi, this is for an assignment so I'm not looking for code. I have to simulate a game where each player has turns and needs to 'pay attention' to what's going on. So far, i know I'll need two threads for each player, one that will sleep until the player's turn and the other paying attention. My question is: Should I work each player as a 'fork' and the threads on the fork, or just create some threads for the player and associate them somehow? It's the first time I've worked with concurrency, semaphores and threads so I'm not sure about the good practices and programming style. Thanks!

    Read the article

  • Int or NSInteger as object for method argument. Objective-C

    - by sergiobuj
    Hi. I'm having some trouble passing a number as an argument for a method: -(void) meth2:(int)next_int; And to call that method i need this: int next_int = 1; [self performSelectorOnMainThread:@selector(meth2:) withObject:next_int waitUntilDone:NO]; //update next_int and call meth2 again at this point i get a "pointer from integer without a cast" error, and would happen the same with a NSInteger. A NSNumber is not useful because it's immutable and i need to change the value constantly. Any Idea how can i do this? Thanks.

    Read the article

  • pthread with unique struct as parameter C

    - by sergiobuj
    Hi, i have this piece of code that is giving me trouble. I know all the threads are reading the same struct. But i have no idea how to fix this. #include <pthread.h> #include <stdio.h> #include <stdlib.h> typedef struct { int a,b; } s_param; void * threadfunc(void *parm) { s_param *param2 = parm; printf("ID:%d and v:%d\n",param2->a,param2->b); pthread_exit(NULL); } int main(int argc, char **argv) { pthread_t thread[3]; int rc=0,i; void * status; for(i=0; i<3 ; ++i){ s_param param; param.b=10; param.a=i; rc = pthread_create(&thread[i], NULL, threadfunc, &param ); // !!!! if(rc){ exit(1); } } for(i=0; i<3 ; ++i){ pthread_join(thread[i],&status); } return 0; } output: ID:2 and v:10 ID:2 and v:10 ID:2 and v:10 and what i need: ID:0 and v:10 ID:1 and v:10 ID:2 and v:10 Thank you.

    Read the article

  • timeout stringwithcontentsofurl

    - by sergiobuj
    Hi, I have this call to stringwithcontentsofurl: [NSString stringWithContentsOfURL:url usedEncoding:NSASCIIStringEncoding error:nil]; How can I give that a simple timeout? I don't want to use threads or operation queues (the content of the url is about 100 characters), I just don't want to wait too long when the connection is slow.

    Read the article

1