Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:30:25+00:00 2026-05-22T22:30:25+00:00

I am a beginner in developing iPhone applications. I was doing this sample program

  • 0

I am a beginner in developing iPhone applications.
I was doing this sample program below and got an error- invalid use of void expression

threadsss.h
------------
#import <Foundation/Foundation.h>

@interface threadsss : NSObject {

    BOOL m_bRunThread;
    int a,b,c;

}
-(void)Thread;
-(void)add;
-(void)display;
@end

threadsss.m
------------

#import "threadsss.h"


@implementation threadsss
-(void)Thread
{
    m_bRunThread = YES;
    NSOperationQueue* queue = [[NSOperationQueue alloc]init];
    NSInvocationOperation* operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(display) object:nil];
    [operation addDependency:[self add]];
    [queue addOperation:operation];
    [queue release];
}
-(void)add
{
    NSLog(@"Going to add a and b!!");
    a=1;
    b=2;
    c = a + b;
    NSLog(@"Finished adding!!");
}
-(void)display
{
    NSLog(@"Into the display method");
    NSLog(@"The value od c is:%d",c);
}
@end

main.m
-------
#import <Foundation/Foundation.h>
#import "threadsss.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    threadsss* thread = [[threadss alloc]init];
    [thread Thread];

    [pool drain];
    return 0;
}

I want to make an asynchronous call between the add and the display methods.After calling the display method i want to execute the add method. and in the meanwhile after printing the “I’m into the display method” the display method will wait for the add to perform its operation and the add after doing its operation will notify its completion to the display method.The display method will then print the result c.

I have tried to implement it with that in my mind.Do i need to do any other modification in my program or is the way i have implemented through dependecies is correct.

EDITED

threadss.h
-----------

#import <Foundation/Foundation.h>


@interface threadss : NSObject {

    BOOL m_bRunThread;
    int a,b,c;
    NSOperationQueue* queue;
    NSInvocationOperation* operation;
    NSInvocationOperation* operation1;
    NSConditionLock* theConditionLock;

}
-(void)Thread;
-(void)add;
-(void)display;
@end


threadss.m
-----------

#import "threadss.h"


@implementation threadss

-(id)init
{
    if (self = [super init]) {
     queue = [[NSOperationQueue alloc]init];
     operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(display) object:nil];
     operation1 = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(add) object:nil];
     theConditionLock = [[NSConditionLock alloc]init];
    }
    return self;
}
-(void)Thread
{
    m_bRunThread = YES;

    //[operation addDependency:operation1];
    if (m_bRunThread) {
    [queue addOperation:operation];
    }
    //[operation addDependency:operation1];
    [queue addOperation:operation1];

    //[self performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES];
    //NSLog(@"I'm going to do the asynchronous communication btwn the threads!!");
    //[self add];
    //[operation addDependency:self];
    sleep(1);
    [queue release];
    [operation release];
    //[operation1 release];
}
-(void)add
{
    NSLog(@"Going to add a and b!!");
    a=1;
    b=2;
    c = a + b;
    NSLog(@"Finished adding!!");
}
-(void)display
{
    NSLog(@"Into the display method");
    [operation1 waitUntilFinished];
    NSLog(@"The Result is:%d",c);

}
@end

main.m
------

#import <Foundation/Foundation.h>
#import "threadss.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    threadss* thread = [[threadss alloc]init];
    [thread Thread];

    [pool drain];
    return 0;
}

I made two operation queues.

But using waitUntilFinished on the same queue may lead to deadlock.How do i do the wait in display method for the add operation to complete its execution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:30:26+00:00Added an answer on May 22, 2026 at 10:30 pm

    First, it would be easier to answer your question if you identified the line than the compiler was complaining about and showing only the relevant code. However, in this case it’s pretty straight-forward. It’s this line:

    [operation addDependency:[self add]];
    

    The add method returns nothing (void). And you’re telling operation to add that as a dependency. What does that mean?

    Either, you should change add to return self or call add on the line before:

    [self add];
    [operation addDependency:self];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m the beginner in iphone software development. I developing the application on skin
I am developing an iPhone app using cocos2d and box2d.In this app i require
What database should a beginner use in the C language? Can I use MySQL?
The very common beginner mistake is when you try to use a class property
I am a beginner in developing websites by Django. I run small discussion websites
I'm developing a module which alter display of add/edit node forms. I'm a beginner
Where can I find tutorials and other beginner-level learning material for developing Windows Mobile
I'm developing a web site with asp.net on localhost, I'm beginner. I wrote a
I am a beginner in Design Patterns. Suppose I am developing a C# application
I am just a beginner in i-phone development and right now i am developing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.